summaryrefslogtreecommitdiffstats
path: root/app/oled.c
diff options
context:
space:
mode:
Diffstat (limited to 'app/oled.c')
-rw-r--r--app/oled.c112
1 files changed, 51 insertions, 61 deletions
diff --git a/app/oled.c b/app/oled.c
index e0c0bee..e5edfed 100644
--- a/app/oled.c
+++ b/app/oled.c
@@ -2,36 +2,34 @@
int
-ssd1306_cmds (uint32_t i2c, uint8_t * buf, size_t len, int delay)
+ssd1306_cmds (uint32_t i2c, uint8_t *buf, size_t len, int delay)
{
int ret = -1;
- while (i2c_lock ());
+ while (i2c_lock());
- do
- {
+ do {
- if (i2cp_start_transaction (i2c, SSD1306_I2C_ADDRESS, I2C_WRITE))
- break;
+ if (i2cp_start_transaction (i2c, SSD1306_I2C_ADDRESS, I2C_WRITE))
+ break;
+
+ if (i2cp_send (i2c, SSD1306_COMMAND))
+ break;
- if (i2cp_send (i2c, SSD1306_COMMAND))
+ while (len--)
+ if (i2cp_send (i2c, * (buf++)))
break;
- while (len--)
- if (i2cp_send (i2c, *(buf++)))
- break;
+ i2cp_stop (i2c);
- i2cp_stop (i2c);
+ if (delay)
+ delay_us (delay);
- if (delay)
- delay_us (delay);
+ ret = 0;
+ } while (0);
- ret = 0;
- }
- while (0);
-
- i2c_unlock ();
+ i2c_unlock();
return ret;
@@ -46,7 +44,7 @@ ssd1306_cmd (uint32_t i2c, uint8_t cmd, int delay)
void
-oled_generate_stream (uint8_t * vram)
+oled_generate_stream (uint8_t *vram)
{
memset (vram, 0, DMA_BUF_SZ);
vram[0] = SSD1306_DATA_CONTINUE;
@@ -56,7 +54,7 @@ oled_generate_stream (uint8_t * vram)
void
-oled_cls (uint8_t * vram)
+oled_cls (uint8_t *vram)
{
memset (vram + 1, 0, SSD1306_VRAM_SIZE);
}
@@ -91,16 +89,16 @@ oled_squirt (void)
ssd1306_cmds (cmds, sizeof (cmds), 0);
- while (i2c_lock ());
+ while (i2c_lock());
i2cp_start_transaction (SSD1306_I2C_ADDRESS, I2C_WRITE);
for (i = 0; i < DMA_BUF_SZ; ++i)
i2cp_send (update_buf[i]);
- i2cp_stop ();
+ i2cp_stop();
- i2c_unlock ();
+ i2c_unlock();
}
#endif
@@ -133,57 +131,49 @@ oled_reset (uint32_t i2c)
void
-oled_const_strip (uint8_t * vram, int x, int xe, uint8_t and, uint8_t or)
+oled_const_strip (uint8_t *vram, int x, int xe, uint8_t and, uint8_t or)
{
uint8_t r;
- for (x++; x <= xe; ++x)
- {
- r = vram[x] & and;
- vram[x] = r | or;
- }
+ for (x++; x <= xe; ++x) {
+ r = vram[x] & and;
+ vram[x] = r | or;
+ }
}
void
-oled_blit_strip (uint8_t * vram, int x, int xe, uint8_t mask, int shift,
- uint8_t * src)
+oled_blit_strip (uint8_t *vram, int x, int xe, uint8_t mask, int shift,
+ uint8_t *src)
{
uint8_t r, s;
- if (shift > 0)
- {
- for (x++; x <= xe; ++x)
- {
- s = *(src++);
- s <<= shift;
- s &= mask;
- r = vram[x] & ~mask;
- vram[x] = r | s;
+ if (shift > 0) {
+ for (x++; x <= xe; ++x) {
+ s = * (src++);
+ s <<= shift;
+ s &= mask;
+ r = vram[x] & ~mask;
+ vram[x] = r | s;
- }
}
- else if (shift < 0)
- {
- shift = -shift;
- for (x++; x <= xe; ++x)
- {
- s = *(src++);
- s >>= shift;
- s &= mask;
- r = vram[x] & ~mask;
- vram[x] = r | s;
- }
+ } else if (shift < 0) {
+ shift = -shift;
+
+ for (x++; x <= xe; ++x) {
+ s = * (src++);
+ s >>= shift;
+ s &= mask;
+ r = vram[x] & ~mask;
+ vram[x] = r | s;
}
- else
- {
- for (x++; x <= xe; ++x)
- {
- s = *(src++);
- s &= mask;
- r = vram[x] & ~mask;
- vram[x] = r | s;
- }
+ } else {
+ for (x++; x <= xe; ++x) {
+ s = * (src++);
+ s &= mask;
+ r = vram[x] & ~mask;
+ vram[x] = r | s;
}
+ }
}