Basic delay for Max7219 on ARM

2.0.x
Scott Lahteine 7 years ago
parent 7b6e742436
commit 212e52e485

@ -64,40 +64,46 @@
static uint8_t LEDs[8] = { 0 };
#ifdef CPU_32_BIT
void MS_DELAY() { DELAY_1US; } // 32-bit processors need a delay to stabilize the signal
// Approximate a 1µs delay on 32-bit ARM
void SIG_DELAY() {
int16_t delay_cycles = CYCLES_PER_MICROSECOND - 10;
while (delay_cycles >= 10) { DELAY_NOPS(6); delay_cycles -= 10; }
if (delay_cycles > 0) DELAY_NOPS(delay_cycles);
}
#else
#define MS_DELAY() DELAY_3_NOP
// Delay for 0.1875µs (16MHz AVR) or 0.15µs (20MHz AVR)
#define SIG_DELAY() DELAY_3_NOP
#endif
void Max7219_PutByte(uint8_t data) {
CRITICAL_SECTION_START
CRITICAL_SECTION_START;
for (uint8_t i = 8; i--;) {
MS_DELAY();
SIG_DELAY();
WRITE(MAX7219_CLK_PIN, LOW); // tick
MS_DELAY();
SIG_DELAY();
WRITE(MAX7219_DIN_PIN, (data & 0x80) ? HIGH : LOW); // send 1 or 0 based on data bit
MS_DELAY();
SIG_DELAY();
WRITE(MAX7219_CLK_PIN, HIGH); // tock
MS_DELAY();
SIG_DELAY();
data <<= 1;
}
CRITICAL_SECTION_END
CRITICAL_SECTION_END;
}
void Max7219(const uint8_t reg, const uint8_t data) {
MS_DELAY();
CRITICAL_SECTION_START
SIG_DELAY();
CRITICAL_SECTION_START;
WRITE(MAX7219_LOAD_PIN, LOW); // begin
MS_DELAY();
SIG_DELAY();
Max7219_PutByte(reg); // specify register
MS_DELAY();
SIG_DELAY();
Max7219_PutByte(data); // put data
MS_DELAY();
SIG_DELAY();
WRITE(MAX7219_LOAD_PIN, LOW); // and tell the chip to load the data
MS_DELAY();
SIG_DELAY();
WRITE(MAX7219_LOAD_PIN, HIGH);
CRITICAL_SECTION_END
MS_DELAY();
CRITICAL_SECTION_END;
SIG_DELAY();
}
void Max7219_LED_Set(const uint8_t col, const uint8_t row, const bool on) {
@ -278,14 +284,14 @@ void Max7219_init() {
*/
void Max7219_idle_tasks() {
#if MAX7219_DEBUG_STEPPER_HEAD || MAX7219_DEBUG_STEPPER_TAIL || MAX7219_DEBUG_STEPPER_QUEUE
CRITICAL_SECTION_START
CRITICAL_SECTION_START;
#if MAX7219_DEBUG_STEPPER_HEAD || MAX7219_DEBUG_STEPPER_QUEUE
const uint8_t head = planner.block_buffer_head;
#endif
#if MAX7219_DEBUG_STEPPER_TAIL || MAX7219_DEBUG_STEPPER_QUEUE
const uint8_t tail = planner.block_buffer_tail;
#endif
CRITICAL_SECTION_END
CRITICAL_SECTION_END;
#endif
static uint16_t refresh_cnt = 0; // The Max7219 circuit boards available for several dollars on eBay

Loading…
Cancel
Save