aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Albers Raviola <thomas@thomaslabs.org>2024-12-03 21:52:59 +0100
committerThomas Albers Raviola <thomas@thomaslabs.org>2024-12-03 21:52:59 +0100
commit7a8c601eec433f7c75d3291d64bb3d41fe50c8ae (patch)
tree1b1038a4dc80cc496a4c608ea760300f8b6d68f1
parent08b7ee440269c881546421da6efe1b6ae122b566 (diff)
Use custom types
-rw-r--r--include/fifo.h12
-rw-r--r--include/i2c.h6
-rw-r--r--include/input.h2
-rw-r--r--include/tft.h7
-rw-r--r--include/tty.h2
-rw-r--r--src/font.c4
-rw-r--r--src/i2c.c14
-rw-r--r--src/menu.c22
-rw-r--r--src/tft.c10
-rw-r--r--src/tty.c20
10 files changed, 49 insertions, 50 deletions
diff --git a/include/fifo.h b/include/fifo.h
index c6eee2d..5fec62f 100644
--- a/include/fifo.h
+++ b/include/fifo.h
@@ -6,22 +6,22 @@
#define FIFO_LEN 32
struct fifo {
- uint8_t head;
- uint8_t tail;
- uint8_t data[FIFO_LEN];
+ u8 head;
+ u8 tail;
+ u8 data[FIFO_LEN];
};
-static inline uint8_t
+static inline u8
fifo_pop(struct fifo *fifo)
{
- uint8_t ret = fifo->data[fifo->head];
+ u8 ret = fifo->data[fifo->head];
if (++fifo->head >= LENGTH(fifo->data))
fifo->head = 0;
return ret;
}
static inline void
-fifo_push(struct fifo *fifo, uint8_t v)
+fifo_push(struct fifo *fifo, u8 v)
{
fifo->data[fifo->tail] = v;
diff --git a/include/i2c.h b/include/i2c.h
index 18fa5e9..a43744a 100644
--- a/include/i2c.h
+++ b/include/i2c.h
@@ -1,7 +1,7 @@
#ifndef I2C_H
#define I2C_H
-#include <stdint.h>
+#include <zeta.h>
#define NACK 0
#define ACK 1
@@ -16,9 +16,9 @@ void
i2c_stop_condition(void);
void
-i2c_send(uint8_t b);
+i2c_send(u8 b);
uint8_t
-i2c_recv(uint8_t ack);
+i2c_recv(u8 ack);
#endif // I2C_H
diff --git a/include/input.h b/include/input.h
index a2f03e2..2f4f05a 100644
--- a/include/input.h
+++ b/include/input.h
@@ -3,7 +3,7 @@
#include <fifo.h>
-static inline uint8_t
+static inline u8
poll_keys(void)
{
return (port_b_data & 0x7C) >> 2;
diff --git a/include/tft.h b/include/tft.h
index 1e2fce2..c7dd680 100644
--- a/include/tft.h
+++ b/include/tft.h
@@ -1,8 +1,7 @@
#ifndef TFT_H
#define TFT_H
-#include <hardware.h>
-#include <stdint.h>
+#include <zeta.h>
#define TFT_WIDTH 480
#define TFT_HEIGHT 320
@@ -112,14 +111,14 @@ tft_ram_wr(void)
}
static inline void
-tft_pixel(uint8_t r, uint8_t g, uint8_t b)
+tft_pixel(u8 r, u8 g, u8 b)
{
tft_data = (r << 3) | ((g & 0x38) >> 3);
tft_data = ((g & 0x07) << 5) | b & 0x1F;
}
void
-tft_set_area(unsigned int x, unsigned int y, unsigned int w, unsigned int h);
+tft_set_area(u16 x, u16 y, u16 w, u16 h);
void
tft_init(void);
diff --git a/include/tty.h b/include/tty.h
index ea73e5f..b48993d 100644
--- a/include/tty.h
+++ b/include/tty.h
@@ -12,7 +12,7 @@ void
addstr(const char *str);
void
-setcur(unsigned int ncol, unsigned int nrow);
+setcur(u16 ncol, u16 nrow);
void
swap_colors(void);
diff --git a/src/font.c b/src/font.c
index c6eb038..87d9562 100644
--- a/src/font.c
+++ b/src/font.c
@@ -1,6 +1,6 @@
-#include <stdint.h>
+#include <zeta.h>
-const uint8_t font[97][8] = {
+const u8 font[97][8] = {
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* SPACE */
{0x18, 0x18, 0x18, 0x18, 0x00, 0x00, 0x18, 0x00}, /* ! */
{0x66, 0x66, 0x66, 0x00, 0x00, 0x00, 0x00, 0x00}, /* " */
diff --git a/src/i2c.c b/src/i2c.c
index cca68c6..b7bf7ab 100644
--- a/src/i2c.c
+++ b/src/i2c.c
@@ -5,7 +5,7 @@
#define SCL (1 << 1)
void
-_delay_ms(uint8_t ms);
+_delay_ms(u8 ms);
void
i2c_start_condition(void)
@@ -36,9 +36,9 @@ i2c_stop_condition(void)
}
void
-i2c_send(uint8_t b)
+i2c_send(u8 b)
{
- uint8_t i;
+ u8 i;
for (i = 0; i < 8; ++i) {
if (b & 1)
@@ -67,11 +67,11 @@ i2c_send(uint8_t b)
port_a_ctrl = 0x7C;
}
-uint8_t
-i2c_recv(uint8_t ack)
+u8
+i2c_recv(u8 ack)
{
- uint8_t i;
- uint8_t b = 0;
+ u8 i;
+ u8 b = 0;
port_a_ctrl = PIO_MODE_3;
port_a_ctrl = 0x7D;
diff --git a/src/menu.c b/src/menu.c
index 320732d..868318b 100644
--- a/src/menu.c
+++ b/src/menu.c
@@ -6,17 +6,17 @@
#include <string.h>
struct time {
- uint8_t second;
- uint8_t minute;
- uint8_t hour;
- uint8_t wkday;
- uint8_t date;
- uint8_t month;
- uint8_t year;
+ u8 second;
+ u8 minute;
+ u8 hour;
+ u8 wkday;
+ u8 date;
+ u8 month;
+ u8 year;
};
struct value {
- uint8_t roll;
+ u8 roll;
int val;
int min, max;
};
@@ -63,7 +63,7 @@ draw_time(void)
void
draw_battery(void)
{
- uint16_t soc = 100; // bat_state_of_charge();
+ u16 soc = 100; // bat_state_of_charge();
char buf[16];
sprintf(buf, "%u%%", soc);
mvaddstr(7, 1, buf);
@@ -73,7 +73,7 @@ void
set_time(void);
struct item {
- uint8_t type;
+ u8 type;
const char *text;
union {
void (*action)(void);
@@ -137,7 +137,7 @@ enum direction {
HORIZONTAL
};
-static uint8_t dir = HORIZONTAL;
+static u8 dir = HORIZONTAL;
static int menu_index = 0;
static int sub_menu_index = -1;
static int edit = 0;
diff --git a/src/tft.c b/src/tft.c
index b75e8bb..8eca5c5 100644
--- a/src/tft.c
+++ b/src/tft.c
@@ -3,7 +3,7 @@
#include <zeta.h>
void
-_delay_ms(uint8_t ms);
+_delay_ms(u8 ms);
/*
* Driver for the ILI9341 TFT Chip
@@ -25,7 +25,7 @@ tft_enable_ext_cmd(void)
}
static inline void
-tft_memory_access_ctrl(uint8_t bits)
+tft_memory_access_ctrl(u8 bits)
{
tft_ctrl = MADCTL;
tft_data = bits;
@@ -43,7 +43,7 @@ tft_display_on(void)
}
static inline void
-tft_pixel_format(uint8_t dbi, uint8_t dpi)
+tft_pixel_format(u8 dbi, u8 dpi)
{
tft_ctrl = COLMOD;
tft_data = (dpi << 4) | dbi;
@@ -60,7 +60,7 @@ tft_set_rgb_interface(void)
}
static inline void
-tft_set_col_addr(uint16_t start, uint16_t end)
+tft_set_col_addr(u16 start, u16 end)
{
tft_ctrl = CASET;
tft_data = start >> 8;
@@ -70,7 +70,7 @@ tft_set_col_addr(uint16_t start, uint16_t end)
}
static inline void
-tft_set_page_addr(uint16_t start, uint16_t end)
+tft_set_page_addr(u16 start, u16 end)
{
tft_ctrl = PASET;
tft_data = start >> 8;
diff --git a/src/tty.c b/src/tty.c
index c630e23..8f6dbaf 100644
--- a/src/tty.c
+++ b/src/tty.c
@@ -6,30 +6,30 @@ struct color {
uint8_t r, g, b;
};
-static unsigned int row = 0;
-static unsigned int col = 0;
+static u16 row = 0;
+static u16 col = 0;
// Index of first row inside buf
-static volatile uint8_t head = 0;
+static volatile u8 head = 0;
// TTY's current contents
-static volatile uint8_t buf[TTY_HEIGHT][TTY_WIDTH];
+static volatile u8 buf[TTY_HEIGHT][TTY_WIDTH];
static volatile struct color bg_color = {0x00, 0x00, 0x00};
static volatile struct color fg_color = {0xFF, 0xFB, 0x00};
-extern const uint8_t font[97][8];
+extern const u8 font[97][8];
-static uint8_t cursor = 0;
-static uint8_t timer = 0;
+static u8 cursor = 0;
+static u8 timer = 0;
u8 blink = 0;
void
blink_cursor(void) __critical __interrupt(3)
{
if (++timer >= 75 && blink) {
- uint8_t i;
+ u8 i;
tft_set_area(8 * col, 8 * row, 8, 8);
tft_ram_wr();
@@ -73,7 +73,7 @@ draw(u8 c)
static void
scroll(void)
{
- uint16_t i, j;
+ u16 i, j;
head = (head + 1) % TTY_HEIGHT;
for (i = head; i < TTY_HEIGHT; ++i) {
@@ -149,7 +149,7 @@ addch(char c)
}
void
-setcur(unsigned int ncol, unsigned int nrow)
+setcur(u16 ncol, u16 nrow)
{
col = ncol;
row = nrow;