summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfishsoupisgood <github@madingley.org>2020-06-14 10:57:41 +0100
committerfishsoupisgood <github@madingley.org>2020-06-14 10:57:41 +0100
commit9f7eb043eae1b5b0196354c373c6aae987695b86 (patch)
treefcb32e318a20c3bf8d9b4d07e80d2cbcbb105e8a
parent0060468326b7ab0cd07d0d80a84118e7c5bcf348 (diff)
downloadrobs_speedo-9f7eb043eae1b5b0196354c373c6aae987695b86.tar.gz
robs_speedo-9f7eb043eae1b5b0196354c373c6aae987695b86.tar.bz2
robs_speedo-9f7eb043eae1b5b0196354c373c6aae987695b86.zip
tidy
-rw-r--r--app/font8x16.c7
-rw-r--r--app/i2c_hw.c37
-rw-r--r--app/led.c10
-rw-r--r--app/main.c30
-rw-r--r--app/oled.c65
-rw-r--r--app/tacho.c40
-rw-r--r--app/usart.c4
7 files changed, 102 insertions, 91 deletions
diff --git a/app/font8x16.c b/app/font8x16.c
index 1a396c7..48358f8 100644
--- a/app/font8x16.c
+++ b/app/font8x16.c
@@ -529,15 +529,16 @@ font8x16_put_ch (unsigned ch, unsigned x, unsigned y)
x += SSD1306_WIDTH;
shift = 8 - shift;
- mask =0xff >> shift;
-
+ mask = 0xff >> shift;
+
if (shift)
{
oled_blit_strip (x, x + 8, mask, -shift, font8x16[ch]);
}
shift = y & 7;
- oled_blit_strip (x, x + 8,~mask & (0xff << shift ) , shift, &font8x16[ch][8]);
+ oled_blit_strip (x, x + 8, ~mask & (0xff << shift), shift,
+ &font8x16[ch][8]);
if (shift)
{
diff --git a/app/i2c_hw.c b/app/i2c_hw.c
index 7fc901e..1dd352c 100644
--- a/app/i2c_hw.c
+++ b/app/i2c_hw.c
@@ -64,7 +64,7 @@ int
i2cp_send (uint8_t v)
{
uint32_t reg;
- uint32_t timeout=1000;
+ uint32_t timeout = 1000;
i2c_send_data (I2C, v);
@@ -77,7 +77,8 @@ i2cp_send (uint8_t v)
reg & ~(I2C_SR1_BERR | I2C_SR1_ARLO | I2C_SR1_AF | I2C_SR1_PECERR |
I2C_SR1_TIMEOUT | I2C_SR1_SMBALERT);
- if (!timeout) return 1;
+ if (!timeout)
+ return 1;
return (reg & I2C_SR1_BTF) ? 0 : -1;
@@ -89,13 +90,14 @@ i2cp_start_transaction (uint8_t a, int wnr)
{
uint32_t reg;
uint32_t __attribute__((unused)) dummy;
- uint32_t timeout=1000;
+ uint32_t timeout = 1000;
i2c_send_start (I2C);
while (!((I2C_SR1 (I2C) & I2C_SR1_SB)
& (I2C_SR2 (I2C) & (I2C_SR2_MSL | I2C_SR2_BUSY))) && (timeout--));
- if (!timeout) return -1;
+ if (!timeout)
+ return -1;
i2c_send_7bit_address (I2C, a, wnr);
@@ -104,7 +106,8 @@ i2cp_start_transaction (uint8_t a, int wnr)
I2C_SR1 (I2C)) & (I2C_SR1_ADDR | I2C_SR1_BERR | I2C_SR1_ARLO |
I2C_SR1_AF | I2C_SR1_PECERR | I2C_SR1_TIMEOUT |
I2C_SR1_SMBALERT)) && (timeout--));
- if (!timeout) return -1;
+ if (!timeout)
+ return -1;
dummy = I2C_SR2 (I2C);
@@ -123,31 +126,31 @@ i2cp_reset_sm (void)
{
int i;
- MAP_OUTPUT_PP(SCL);
- MAP_OUTPUT_PP(SDA);
+ MAP_OUTPUT_PP (SCL);
+ MAP_OUTPUT_PP (SDA);
- SET(SDA);
- SET(SCL);
+ SET (SDA);
+ SET (SCL);
delay_us (10);
- CLEAR(SDA);
+ CLEAR (SDA);
delay_us (10);
- CLEAR(SCL);
+ CLEAR (SCL);
for (i = 0; i < 9; ++i)
{
delay_us (10);
- SET(SCL);
+ SET (SCL);
delay_us (10);
- CLEAR(SCL);
+ CLEAR (SCL);
delay_us (10);
}
- SET(SCL);
+ SET (SCL);
delay_us (10);
- SET(SDA);
+ SET (SDA);
delay_us (10);
- MAP_AF_OD(SCL);
- MAP_AF_OD(SDA);
+ MAP_AF_OD (SCL);
+ MAP_AF_OD (SDA);
}
diff --git a/app/led.c b/app/led.c
index a6bd8ea..9dcc543 100644
--- a/app/led.c
+++ b/app/led.c
@@ -9,8 +9,8 @@ static int led = 0;
void
led_init (void)
{
- MAP_OUTPUT_OD(LED);
- SET(LED);
+ MAP_OUTPUT_OD (LED);
+ SET (LED);
}
@@ -18,14 +18,14 @@ led_init (void)
void
led_clear (void)
{
- SET(LED);
- led =0;
+ SET (LED);
+ led = 0;
}
void
led_set (void)
{
- CLEAR(LED);
+ CLEAR (LED);
led = 200;
}
diff --git a/app/main.c b/app/main.c
index ee0dd40..1106316 100644
--- a/app/main.c
+++ b/app/main.c
@@ -6,7 +6,7 @@
int
main (void)
{
- unsigned cnt=0;
+ unsigned cnt = 0;
//nvic_set_priority_grouping(NVIC_PriorityGroup_4);
@@ -21,15 +21,15 @@ main (void)
/*Adjust interrupt priorities so that taco trumps uarts trumps timer trumps dma */
- nvic_set_priority (TACHO_IRQ,0x20);
+ nvic_set_priority (TACHO_IRQ, 0x20);
nvic_set_priority (NVIC_USART1_IRQ, 0x40);
nvic_set_priority (NVIC_SYSTICK_IRQ, 0x60);
nvic_set_priority (NVIC_DMA1_CHANNEL6_IRQ, 0x80);
- /* Claw some pins pack*/
+ /* Claw some pins pack */
gpio_primary_remap (AFIO_MAPR_SWJ_CFG_JTAG_OFF_SW_ON, 0);
- dwt_enable_cycle_counter();
+ dwt_enable_cycle_counter ();
ticker_init ();
@@ -44,28 +44,28 @@ main (void)
oled_init ();
- tacho_init();
+ tacho_init ();
font8x8_put_str ("ABC fish soup!", 0, 0);
- MAP_OUTPUT_PP(WIGGLE);
+ MAP_OUTPUT_PP (WIGGLE);
for (;;)
{
- char buf[20];
+ char buf[20];
- sprintf(buf,"%6u rpm",(unsigned) raw_tacho);
- font8x16_put_str (buf, 30, 8);
+ sprintf (buf, "%6u rpm", (unsigned) raw_tacho);
+ font8x16_put_str (buf, 30, 8);
- sprintf(buf,"%8d",cnt++);
- font8x8_put_str (buf, 0, 24);
+ sprintf (buf, "%8d", cnt++);
+ font8x8_put_str (buf, 0, 24);
- if (cnt&1)
- SET(WIGGLE);
- else
- CLEAR(WIGGLE);
+ if (cnt & 1)
+ SET (WIGGLE);
+ else
+ CLEAR (WIGGLE);
}
diff --git a/app/oled.c b/app/oled.c
index 69b2580..dec54f2 100644
--- a/app/oled.c
+++ b/app/oled.c
@@ -8,36 +8,38 @@ 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;
+static int oled_sad = 0;
int
ssd1306_cmds (uint8_t * buf, size_t len, int delay)
{
- int ret=-1;
+ int ret = -1;
while (i2c_lock ());
- do {
+ do
+ {
- if (i2cp_start_transaction (SSD1306_I2C_ADDRESS, I2C_WRITE))
- break;
+ if (i2cp_start_transaction (SSD1306_I2C_ADDRESS, I2C_WRITE))
+ break;
- if (i2cp_send (SSD1306_COMMAND))
- break;
-
- while (len--)
- if (i2cp_send (*(buf++)))
- break;
+ if (i2cp_send (SSD1306_COMMAND))
+ break;
- i2cp_stop ();
+ while (len--)
+ if (i2cp_send (*(buf++)))
+ break;
+
+ i2cp_stop ();
- if (delay)
- delay_us (delay);
+ if (delay)
+ delay_us (delay);
- ret=0;
- } while(0);
+ ret = 0;
+ }
+ while (0);
i2c_unlock ();
@@ -67,15 +69,17 @@ start_dma (void)
memcpy (dma_buf, update_buf, DMA_BUF_SZ);
- if (ssd1306_cmds (cmds, sizeof (cmds), 0)) {
- oled_sad++;
- return;
- }
-
- if (i2cp_start_transaction (SSD1306_I2C_ADDRESS, I2C_WRITE)) {
- oled_sad++;
- return;
- }
+ 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;
@@ -122,11 +126,12 @@ oled_refresh_wdt (void)
i2cp_stop ();
dma_in_progress = 0;
- if (oled_sad) {
- oled_sad=0;
- i2cp_reset_sm();
- }
-
+ if (oled_sad)
+ {
+ oled_sad = 0;
+ i2cp_reset_sm ();
+ }
+
start_dma ();
}
diff --git a/app/tacho.c b/app/tacho.c
index 35331da..96a4d1b 100644
--- a/app/tacho.c
+++ b/app/tacho.c
@@ -1,6 +1,6 @@
#include "project.h"
-#define SPURIOUS MS(10) /*Anything faster than 6000rpm is a false trigger */
+#define SPURIOUS MS(10) /*Anything faster than 6000rpm is a false trigger */
@@ -14,44 +14,49 @@ cycle_diff (uint32_t a, uint32_t b)
-void exti3_isr (void)
+void
+exti3_isr (void)
{
-uint32_t now, diff;
-static uint32_t last_edge;
+ uint32_t now, diff;
+ static uint32_t last_edge;
-if (!( EXTI_PR & TACHO)) return;
+ if (!(EXTI_PR & TACHO))
+ return;
-EXTI_PR=TACHO;
+ EXTI_PR = TACHO;
-now=dwt_read_cycle_counter();
+ now = dwt_read_cycle_counter ();
-diff= cycle_diff(last_edge,now);
+ diff = cycle_diff (last_edge, now);
-if (diff < SPURIOUS) return;
+ if (diff < SPURIOUS)
+ return;
-last_edge=now;
+ last_edge = now;
/* Want RPM, diff is in units of 1/72 us */
-if (!diff) return;
+ if (!diff)
+ return;
/* uint32_t is able to express 60s in clock ticks, so divide everything by 2 */
-diff >>=1;
+ diff >>= 1;
-
-raw_tacho =(US ((60*1000000)/2))/diff;
+
+ raw_tacho = (US ((60 * 1000000) / 2)) / diff;
}
-void tacho_init (void)
+void
+tacho_init (void)
{
MAP_INPUT_PU (TACHO);
- exti_select_source (TACHO,TACHO_PORT);
+ exti_select_source (TACHO, TACHO_PORT);
exti_set_trigger (TACHO, EXTI_TRIGGER_FALLING);
exti_enable_request (TACHO);
exti_reset_request (TACHO);
@@ -59,6 +64,3 @@ void tacho_init (void)
nvic_enable_irq (TACHO_IRQ);
}
-
-
-
diff --git a/app/usart.c b/app/usart.c
index 29a2978..163fe4f 100644
--- a/app/usart.c
+++ b/app/usart.c
@@ -105,8 +105,8 @@ usart_init (void)
nvic_enable_irq (NVIC_USART1_IRQ);
/* Map pins, and usart1 to have pull ups */
- MAP_AF_PP(USART1_TX);
- MAP_INPUT_PU(USART1_RX);
+ MAP_AF_PP (USART1_TX);
+ MAP_INPUT_PU (USART1_RX);
/* Setup UART1 parameters. */