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>
This commit is contained in:
parent
a3980cebcc
commit
effe6f6ddd
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue