summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfishsoupisgood <github@madingley.org>2020-06-14 09:31:59 +0100
committerfishsoupisgood <github@madingley.org>2020-06-14 09:31:59 +0100
commitdbc21c1e5dfd95248fe2cd7da6d96c92bdbb97a4 (patch)
tree0ecfa6277c11d8f8d62be8d80abfa6d29927a336
parent94488c326b162c109c71abd015a29f0711db2178 (diff)
downloadrobs_speedo-dbc21c1e5dfd95248fe2cd7da6d96c92bdbb97a4.tar.gz
robs_speedo-dbc21c1e5dfd95248fe2cd7da6d96c92bdbb97a4.tar.bz2
robs_speedo-dbc21c1e5dfd95248fe2cd7da6d96c92bdbb97a4.zip
all loops terminate
-rw-r--r--app/.gitignore5
-rw-r--r--app/i2c_hw.c25
-rw-r--r--app/main.c5
-rw-r--r--app/oled.c48
-rw-r--r--app/prototypes.h11
5 files changed, 63 insertions, 31 deletions
diff --git a/app/.gitignore b/app/.gitignore
new file mode 100644
index 0000000..6d83155
--- /dev/null
+++ b/app/.gitignore
@@ -0,0 +1,5 @@
+*.d
+*.o
+*.elf
+*.map
+*.hex
diff --git a/app/i2c_hw.c b/app/i2c_hw.c
index b709af0..d7989a9 100644
--- a/app/i2c_hw.c
+++ b/app/i2c_hw.c
@@ -62,6 +62,7 @@ int
i2cp_send (uint8_t v)
{
uint32_t reg;
+ uint32_t timeout=1000;
i2c_send_data (I2C, v);
@@ -69,11 +70,13 @@ i2cp_send (uint8_t v)
((reg =
I2C_SR1 (I2C)) & (I2C_SR1_BTF | I2C_SR1_BERR | I2C_SR1_ARLO |
I2C_SR1_AF | I2C_SR1_PECERR | I2C_SR1_TIMEOUT |
- I2C_SR1_SMBALERT)));
+ I2C_SR1_SMBALERT)) && (timeout--));
I2C_SR1 (I2C) =
reg & ~(I2C_SR1_BERR | I2C_SR1_ARLO | I2C_SR1_AF | I2C_SR1_PECERR |
I2C_SR1_TIMEOUT | I2C_SR1_SMBALERT);
+ if (!timeout) return 1;
+
return (reg & I2C_SR1_BTF) ? 0 : -1;
}
@@ -84,10 +87,13 @@ i2cp_start_transaction (uint8_t a, int wnr)
{
uint32_t reg;
uint32_t __attribute__((unused)) dummy;
+ uint32_t timeout=1000;
i2c_send_start (I2C);
while (!((I2C_SR1 (I2C) & I2C_SR1_SB)
- & (I2C_SR2 (I2C) & (I2C_SR2_MSL | I2C_SR2_BUSY))));
+ & (I2C_SR2 (I2C) & (I2C_SR2_MSL | I2C_SR2_BUSY))) && (timeout--));
+
+ if (!timeout) return -1;
i2c_send_7bit_address (I2C, a, wnr);
@@ -95,7 +101,9 @@ i2cp_start_transaction (uint8_t a, int wnr)
((reg =
I2C_SR1 (I2C)) & (I2C_SR1_ADDR | I2C_SR1_BERR | I2C_SR1_ARLO |
I2C_SR1_AF | I2C_SR1_PECERR | I2C_SR1_TIMEOUT |
- I2C_SR1_SMBALERT)));
+ I2C_SR1_SMBALERT)) && (timeout--));
+ if (!timeout) return -1;
+
dummy = I2C_SR2 (I2C);
I2C_SR1 (I2C) =
@@ -108,7 +116,7 @@ i2cp_start_transaction (uint8_t a, int wnr)
/*This is stupid, it bit bangs a dummy transaction to get the host i2c controller back in the game */
-static void
+void
i2cp_reset_sm (void)
{
int i;
@@ -136,6 +144,11 @@ i2cp_reset_sm (void)
gpio_set (GPIOB, GPIO_I2C1_SDA);
delay_us (10);
+ gpio_set_mode (GPIOB, GPIO_MODE_OUTPUT_50_MHZ,
+ GPIO_CNF_OUTPUT_ALTFN_OPENDRAIN,
+ GPIO_I2C1_SCL | GPIO_I2C1_SDA);
+
+
}
void
@@ -245,10 +258,6 @@ i2cp_init (void)
i2cp_reset_sm ();
- gpio_set_mode (GPIOB, GPIO_MODE_OUTPUT_50_MHZ,
- GPIO_CNF_OUTPUT_ALTFN_OPENDRAIN,
- GPIO_I2C1_SCL | GPIO_I2C1_SDA);
-
i2c_set_clock_frequency (I2C, I2C_CR2_FREQ_36MHZ);
i2c_set_standard_mode (I2C);
i2c_set_ccr (I2C, 0x80); /* t_high=t_high=CCR * Tpclk1 */
diff --git a/app/main.c b/app/main.c
index 9d52e1f..c40b571 100644
--- a/app/main.c
+++ b/app/main.c
@@ -43,10 +43,8 @@ main (void)
//i2cb_scan();
- delay_ms (10);
oled_init ();
- delay_ms (4000);
font8x8_put_str ("ABC fish soup!", 0, 0);
@@ -55,8 +53,9 @@ main (void)
char buf[20];
sprintf(buf,"%8d",cnt++);
- font8x16_put_str (buf, 30, 16);
+ font8x16_put_str (buf, 30, 8);
+ font8x8_put_str (buf, 0, 24);
}
diff --git a/app/oled.c b/app/oled.c
index 51cfd9a..69b2580 100644
--- a/app/oled.c
+++ b/app/oled.c
@@ -8,27 +8,41 @@ uint8_t update_buf[DMA_BUF_SZ];
static int dma_in_progress = 0;
static int refresh_enabled = 0;
static uint32_t refresh_wdt = 0;
+static int oled_sad=0;
int
ssd1306_cmds (uint8_t * buf, size_t len, int delay)
{
+ int ret=-1;
+
while (i2c_lock ());
- i2cp_start_transaction (SSD1306_I2C_ADDRESS, I2C_WRITE);
- i2cp_send (SSD1306_COMMAND);
+ do {
+ if (i2cp_start_transaction (SSD1306_I2C_ADDRESS, I2C_WRITE))
+ break;
+
+ if (i2cp_send (SSD1306_COMMAND))
+ break;
+
while (len--)
- i2cp_send (*(buf++));
+ if (i2cp_send (*(buf++)))
+ break;
i2cp_stop ();
if (delay)
delay_us (delay);
+
+ ret=0;
+ } while(0);
+
i2c_unlock ();
- return 0;
+
+ return ret;
}
int
@@ -50,15 +64,22 @@ start_dma (void)
if (dma_in_progress)
return;
- refresh_wdt = 0;
-
- dma_in_progress = 1;
memcpy (dma_buf, update_buf, DMA_BUF_SZ);
- ssd1306_cmds (cmds, sizeof (cmds), 0);
+ if (ssd1306_cmds (cmds, sizeof (cmds), 0)) {
+ oled_sad++;
+ return;
+ }
+
+ if (i2cp_start_transaction (SSD1306_I2C_ADDRESS, I2C_WRITE)) {
+ oled_sad++;
+ return;
+ }
+
+ refresh_wdt = 0;
+ dma_in_progress = 1;
- i2cp_start_transaction (SSD1306_I2C_ADDRESS, I2C_WRITE);
i2cp_start_dma (dma_buf, DMA_BUF_SZ);
}
@@ -85,10 +106,12 @@ oled_refresh_wdt (void)
if (!refresh_enabled)
return;
+
+
refresh_wdt++;
- if (refresh_wdt < 1000)
+ if ((refresh_wdt < 1000) && (!oled_sad))
return;
refresh_wdt = 0;
@@ -99,6 +122,11 @@ oled_refresh_wdt (void)
i2cp_stop ();
dma_in_progress = 0;
+ if (oled_sad) {
+ oled_sad=0;
+ i2cp_reset_sm();
+ }
+
start_dma ();
}
diff --git a/app/prototypes.h b/app/prototypes.h
index 31d9b70..359c826 100644
--- a/app/prototypes.h
+++ b/app/prototypes.h
@@ -53,22 +53,13 @@ extern void i2cp_stop(void);
extern void i2cp_abort_stop(void);
extern int i2cp_send(uint8_t v);
extern int i2cp_start_transaction(uint8_t a, int wnr);
+extern void i2cp_reset_sm(void);
extern void i2cp_start_dma(uint8_t *buf, int len);
extern int i2cp_dma_in_progress(void);
extern void i2cp_stop_dma(void);
extern void i2cp_reset(void);
extern void i2cp_scan(void);
extern void i2cp_init(void);
-/* i2c_bb.c */
-extern uint8_t i2cb_send(uint8_t wot);
-extern uint8_t i2cb_send_addr(uint8_t addr, uint8_t rnw);
-extern uint8_t i2cb_read(uint8_t ack);
-extern void i2cb_start(void);
-extern void i2cb_stop(void);
-extern int i2cb_start_transaction(uint8_t a, uint8_t rnw);
-extern void i2cb_reset(void);
-extern void i2cb_scan(void);
-extern void i2cb_init(void);
/* font8x8.c */
extern void font8x8_put_ch(unsigned ch, unsigned x, unsigned y);
extern void font8x8_put_str(char *str, unsigned x, unsigned y);