mirror of
https://github.com/MarlinFirmware/Marlin.git
synced 2024-11-23 12:04:19 +00:00
Basic delay for Max7219 on ARM
This commit is contained in:
parent
7b6e742436
commit
212e52e485
@ -64,40 +64,46 @@
|
|||||||
static uint8_t LEDs[8] = { 0 };
|
static uint8_t LEDs[8] = { 0 };
|
||||||
|
|
||||||
#ifdef CPU_32_BIT
|
#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
|
#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
|
#endif
|
||||||
|
|
||||||
void Max7219_PutByte(uint8_t data) {
|
void Max7219_PutByte(uint8_t data) {
|
||||||
CRITICAL_SECTION_START
|
CRITICAL_SECTION_START;
|
||||||
for (uint8_t i = 8; i--;) {
|
for (uint8_t i = 8; i--;) {
|
||||||
MS_DELAY();
|
SIG_DELAY();
|
||||||
WRITE(MAX7219_CLK_PIN, LOW); // tick
|
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
|
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
|
WRITE(MAX7219_CLK_PIN, HIGH); // tock
|
||||||
MS_DELAY();
|
SIG_DELAY();
|
||||||
data <<= 1;
|
data <<= 1;
|
||||||
}
|
}
|
||||||
CRITICAL_SECTION_END
|
CRITICAL_SECTION_END;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Max7219(const uint8_t reg, const uint8_t data) {
|
void Max7219(const uint8_t reg, const uint8_t data) {
|
||||||
MS_DELAY();
|
SIG_DELAY();
|
||||||
CRITICAL_SECTION_START
|
CRITICAL_SECTION_START;
|
||||||
WRITE(MAX7219_LOAD_PIN, LOW); // begin
|
WRITE(MAX7219_LOAD_PIN, LOW); // begin
|
||||||
MS_DELAY();
|
SIG_DELAY();
|
||||||
Max7219_PutByte(reg); // specify register
|
Max7219_PutByte(reg); // specify register
|
||||||
MS_DELAY();
|
SIG_DELAY();
|
||||||
Max7219_PutByte(data); // put data
|
Max7219_PutByte(data); // put data
|
||||||
MS_DELAY();
|
SIG_DELAY();
|
||||||
WRITE(MAX7219_LOAD_PIN, LOW); // and tell the chip to load the data
|
WRITE(MAX7219_LOAD_PIN, LOW); // and tell the chip to load the data
|
||||||
MS_DELAY();
|
SIG_DELAY();
|
||||||
WRITE(MAX7219_LOAD_PIN, HIGH);
|
WRITE(MAX7219_LOAD_PIN, HIGH);
|
||||||
CRITICAL_SECTION_END
|
CRITICAL_SECTION_END;
|
||||||
MS_DELAY();
|
SIG_DELAY();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Max7219_LED_Set(const uint8_t col, const uint8_t row, const bool on) {
|
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() {
|
void Max7219_idle_tasks() {
|
||||||
#if MAX7219_DEBUG_STEPPER_HEAD || MAX7219_DEBUG_STEPPER_TAIL || MAX7219_DEBUG_STEPPER_QUEUE
|
#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
|
#if MAX7219_DEBUG_STEPPER_HEAD || MAX7219_DEBUG_STEPPER_QUEUE
|
||||||
const uint8_t head = planner.block_buffer_head;
|
const uint8_t head = planner.block_buffer_head;
|
||||||
#endif
|
#endif
|
||||||
#if MAX7219_DEBUG_STEPPER_TAIL || MAX7219_DEBUG_STEPPER_QUEUE
|
#if MAX7219_DEBUG_STEPPER_TAIL || MAX7219_DEBUG_STEPPER_QUEUE
|
||||||
const uint8_t tail = planner.block_buffer_tail;
|
const uint8_t tail = planner.block_buffer_tail;
|
||||||
#endif
|
#endif
|
||||||
CRITICAL_SECTION_END
|
CRITICAL_SECTION_END;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static uint16_t refresh_cnt = 0; // The Max7219 circuit boards available for several dollars on eBay
|
static uint16_t refresh_cnt = 0; // The Max7219 circuit boards available for several dollars on eBay
|
||||||
|
Loading…
Reference in New Issue
Block a user