diff options
author | Kevin O'Connor <kevin@koconnor.net> | 2019-08-10 11:43:52 -0400 |
---|---|---|
committer | Kevin O'Connor <kevin@koconnor.net> | 2019-08-10 11:45:15 -0400 |
commit | effe6f6ddd5132db4ab4f88bf8616aab575e7691 (patch) | |
tree | 76706f1fd259d99c8af4e4be0bddff72b6100f18 | |
parent | a3980cebcc041d4f07063d17b34837bcba5138a2 (diff) | |
download | kutter-effe6f6ddd5132db4ab4f88bf8616aab575e7691.tar.gz kutter-effe6f6ddd5132db4ab4f88bf8616aab575e7691.tar.xz kutter-effe6f6ddd5132db4ab4f88bf8616aab575e7691.zip |
lcd_st7920: Add brief delay around gpio toggle calls on fast MCUs
On fast MCUs (like the SAMD51) it is possible for the gpio to toggle
faster than the st7920 can accept. Add a small delay around the clock
rise signal.
Signed-off-by: Lars R. Hansen <popshansen@hotmail.com>
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
-rw-r--r-- | src/lcd_st7920.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/lcd_st7920.c b/src/lcd_st7920.c index 8cd76c50..0f6a444d 100644 --- a/src/lcd_st7920.c +++ b/src/lcd_st7920.c @@ -4,6 +4,7 @@ // // This file may be distributed under the terms of the GNU GPLv3 license. +#include "autoconf.h" // CONFIG_CLOCK_FREQ #include "basecmd.h" // oid_alloc #include "board/gpio.h" // gpio_out_write #include "board/irq.h" // irq_poll @@ -21,6 +22,23 @@ struct st7920 { * Transmit functions ****************************************************************/ +static uint32_t +nsecs_to_ticks(uint32_t ns) +{ + return timer_from_us(ns * 1000) / 1000000; +} + +static inline void +ndelay(uint32_t nsecs) +{ + if (CONFIG_CLOCK_FREQ <= 48000000) + // Slower MCUs don't require a delay + return; + uint32_t end = timer_read_time() + nsecs_to_ticks(nsecs); + while (timer_is_before(timer_read_time(), end)) + irq_poll(); +} + #define SYNC_CMD 0xf8 #define SYNC_DATA 0xfa @@ -35,7 +53,9 @@ st7920_xmit_byte(struct st7920 *s, uint8_t data) gpio_out_toggle(sid); data = ~data; } + ndelay(200); gpio_out_toggle(sclk); + ndelay(200); data <<= 1; gpio_out_toggle(sclk); } |