summaryrefslogtreecommitdiff
path: root/fw/fe310
diff options
context:
space:
mode:
Diffstat (limited to 'fw/fe310')
-rw-r--r--fw/fe310/eos/Makefile2
-rw-r--r--fw/fe310/eos/board.h34
-rw-r--r--fw/fe310/eos/eos.c1
-rw-r--r--fw/fe310/eos/eve/clipb.c8
-rw-r--r--fw/fe310/eos/eve/eve.c138
-rw-r--r--fw/fe310/eos/eve/eve_platform.c8
-rw-r--r--fw/fe310/eos/eve/eve_touch.c144
-rw-r--r--fw/fe310/eos/eve/eve_vtrack.c20
-rw-r--r--fw/fe310/eos/eve/screen/window.c8
-rw-r--r--fw/fe310/eos/eve/widget/selectw.c20
-rw-r--r--fw/fe310/eos/eve/widget/strw.c14
-rw-r--r--fw/fe310/eos/eve/widget/textw.c20
-rw-r--r--fw/fe310/eos/i2s.c65
-rw-r--r--fw/fe310/eos/i2s.h8
-rw-r--r--fw/fe310/eos/i2s_def.h27
-rw-r--r--fw/fe310/eos/i2s_priv.h8
-rw-r--r--fw/fe310/eos/interrupt.h2
-rw-r--r--fw/fe310/eos/msgq_priv.h (renamed from fw/fe310/eos/msgq_def.h)0
-rw-r--r--fw/fe310/eos/net.c28
-rw-r--r--fw/fe310/eos/net_def.h13
-rw-r--r--fw/fe310/eos/power.c4
-rw-r--r--fw/fe310/eos/spi.c66
-rw-r--r--fw/fe310/eos/spi.h24
-rw-r--r--fw/fe310/eos/spi_def.h12
-rw-r--r--fw/fe310/eos/spi_dev.c77
-rw-r--r--fw/fe310/eos/spi_dev.h11
-rw-r--r--fw/fe310/eos/spi_priv.h44
-rw-r--r--fw/fe310/eos/trap_entry.S36
-rw-r--r--fw/fe310/eos/uart.c1
29 files changed, 415 insertions, 428 deletions
diff --git a/fw/fe310/eos/Makefile b/fw/fe310/eos/Makefile
index 0b3d6fe..366e69a 100644
--- a/fw/fe310/eos/Makefile
+++ b/fw/fe310/eos/Makefile
@@ -2,7 +2,7 @@ include ../common.mk
CFLAGS += -I. -I../bsp/include -I../bsp/drivers
-obj = trap_entry.o eos.o msgq.o event.o interrupt.o timer.o power.o i2s.o i2c.o uart.o spi.o spi_dev.o net.o wifi.o cell.o sock.o unicode.o
+obj = trap_entry.o eos.o msgq.o event.o interrupt.o timer.o power.o i2s.o i2c.o uart.o spi.o net.o wifi.o cell.o sock.o unicode.o
%.o: %.c %.h
diff --git a/fw/fe310/eos/board.h b/fw/fe310/eos/board.h
new file mode 100644
index 0000000..98741da
--- /dev/null
+++ b/fw/fe310/eos/board.h
@@ -0,0 +1,34 @@
+#define SPI_DIV_NET 16
+#define SPI_DIV_EVE 16
+#define SPI_DIV_SDC 16
+#define SPI_DIV_CAM 16
+
+#define SPI_CSID_NET 3
+#define SPI_CSID_EVE 2
+#define SPI_CSID_SDC 0
+#define SPI_CSID_CAM SPI_CSID_NONE
+
+#define SPI_CSPIN_NET SPI_CSPIN_NONE
+#define SPI_CSPIN_EVE SPI_CSPIN_NONE
+#define SPI_CSPIN_SDC SPI_CSPIN_NONE
+#define SPI_CSPIN_CAM 23
+
+#define NET_PIN_RTS 20
+#define NET_PIN_CTS 22
+
+#define I2S_PIN_CK 1 /* PWM 0.1 */
+#define I2S_PIN_CK_SW 21 /* PWM 1.2 */
+#define I2S_PIN_CK_SR 18
+#define I2S_PIN_WS_MIC 19 /* PWM 1.1 */
+#define I2S_PIN_WS_SPK 11 /* PWM 2.1 */
+#define I2S_PIN_SD_IN 13
+#define I2S_PIN_SD_OUT 12
+
+#define I2S_IRQ_WS_ID (INT_PWM2_BASE + 0)
+#define I2S_IRQ_SD_ID (INT_PWM2_BASE + 3)
+
+#define I2S_CTRL_ADDR_CK PWM0_CTRL_ADDR
+#define I2S_CTRL_ADDR_WS_MIC PWM1_CTRL_ADDR
+#define I2S_CTRL_ADDR_WS_SPK PWM2_CTRL_ADDR
+
+#define I2S_IDLE_CYCLES 8
diff --git a/fw/fe310/eos/eos.c b/fw/fe310/eos/eos.c
index 2a7f992..490e68b 100644
--- a/fw/fe310/eos/eos.c
+++ b/fw/fe310/eos/eos.c
@@ -33,7 +33,6 @@ void eos_init(void) {
eos_wifi_init();
eos_cell_init();
eos_sock_init();
- eos_spi_dev_init();
eos_bq25895_init();
eos_net_wake(wakeup_cause);
diff --git a/fw/fe310/eos/eve/clipb.c b/fw/fe310/eos/eve/clipb.c
index 04c9a46..974b631 100644
--- a/fw/fe310/eos/eve/clipb.c
+++ b/fw/fe310/eos/eve/clipb.c
@@ -3,17 +3,17 @@
#include "eve.h"
#include "clipb.h"
-static uint8_t _clipb[EVE_CLIPB_SIZE_BUF];
+static uint8_t clipb[EVE_CLIPB_SIZE_BUF];
int eve_clipb_push(uint8_t *str, uint16_t len) {
if (len >= EVE_CLIPB_SIZE_BUF) return EVE_ERR;
- memcpy(_clipb, str, len);
- _clipb[len] = '\0';
+ memcpy(clipb, str, len);
+ clipb[len] = '\0';
return EVE_OK;
}
uint8_t *eve_clipb_get(void) {
- return _clipb;
+ return clipb;
} \ No newline at end of file
diff --git a/fw/fe310/eos/eve/eve.c b/fw/fe310/eos/eve/eve.c
index 6809d72..3b56e11 100644
--- a/fw/fe310/eos/eve/eve.c
+++ b/fw/fe310/eos/eve/eve.c
@@ -6,15 +6,15 @@
#define EVE_MEM_WRITE 0x800000
-static char _cmd_burst;
-static uint16_t _cmd_offset;
+static char cmd_burst;
+static uint16_t cmd_offset;
-static char _dl_burst;
-static uint32_t _dl_addr;
+static char dl_burst;
+static uint32_t dl_addr;
-static uint32_t *_touch_calib;
-static uint8_t _brigtness;
-static uint8_t _power_state;
+static uint32_t *touch_calib;
+static uint8_t brigtness;
+static uint8_t power_state;
void eve_command(uint8_t command, uint8_t parameter) {
eve_spi_cs_set();
@@ -95,13 +95,13 @@ void eve_writeb(uint32_t addr, uint8_t *b, size_t size) {
eve_spi_cs_clear();
}
-static void _dl_inc(uint32_t i) {
- _dl_addr += i;
+static void dl_inc(uint32_t i) {
+ dl_addr += i;
}
void eve_dl_start(uint32_t addr, char burst) {
- _dl_addr = addr;
- _dl_burst = burst;
+ dl_addr = addr;
+ dl_burst = burst;
if (burst) {
eve_spi_lock();
eve_spi_cs_set();
@@ -110,20 +110,20 @@ void eve_dl_start(uint32_t addr, char burst) {
}
void eve_dl_write(uint32_t dl) {
- if (_dl_burst) {
+ if (dl_burst) {
eve_spi_xchg32(dl, EVE_SPI_FLAG_TX | EVE_SPI_FLAG_BSWAP);
} else {
- eve_write32(_dl_addr, dl);
+ eve_write32(dl_addr, dl);
}
- _dl_inc(4);
+ dl_inc(4);
}
void eve_dl_end(void) {
- if (_dl_burst) {
+ if (dl_burst) {
eve_spi_flush();
eve_spi_cs_clear();
eve_spi_unlock();
- _dl_burst = 0;
+ dl_burst = 0;
}
}
@@ -132,33 +132,33 @@ void eve_dl_swap(void) {
}
uint32_t eve_dl_get_addr(void) {
- return _dl_addr;
+ return dl_addr;
}
-static void _cmd_inc(uint16_t i) {
- _cmd_offset += i;
- _cmd_offset &= 0x0fff;
+static void cmd_inc(uint16_t i) {
+ cmd_offset += i;
+ cmd_offset &= 0x0fff;
}
-static void _cmd_begin(uint32_t command) {
+static void cmd_begin(uint32_t command) {
uint8_t flags = 0;
- if (_cmd_burst) {
+ if (cmd_burst) {
flags = EVE_SPI_FLAG_TX;
} else {
- uint32_t addr = EVE_RAM_CMD + _cmd_offset;
+ uint32_t addr = EVE_RAM_CMD + cmd_offset;
eve_spi_cs_set();
eve_spi_xchg24(addr | EVE_MEM_WRITE, 0);
}
eve_spi_xchg32(command, EVE_SPI_FLAG_BSWAP | flags);
- _cmd_inc(4);
+ cmd_inc(4);
}
-static void _cmd_end(void) {
- if (!_cmd_burst) eve_spi_cs_clear();
+static void cmd_end(void) {
+ if (!cmd_burst) eve_spi_cs_clear();
}
-static void _cmd_string(const char *s, uint8_t flags) {
+static void cmd_string(const char *s, uint8_t flags) {
int i = 0;
while (s[i] != 0) {
@@ -167,68 +167,68 @@ static void _cmd_string(const char *s, uint8_t flags) {
}
eve_spi_xchg8(0, flags);
i++;
- _cmd_inc(i);
+ cmd_inc(i);
}
-static void _cmd_buffer(const char *b, int size, uint8_t flags) {
+static void cmd_buffer(const char *b, int size, uint8_t flags) {
int i = 0;
for (i=0; i<size; i++) {
eve_spi_xchg8(b[i], flags);
}
- _cmd_inc(size);
+ cmd_inc(size);
}
void eve_cmd(uint32_t cmd, const char *fmt, ...) {
- uint8_t flags = _cmd_burst ? (EVE_SPI_FLAG_TX | EVE_SPI_FLAG_BSWAP) : EVE_SPI_FLAG_BSWAP;
+ uint8_t flags = cmd_burst ? (EVE_SPI_FLAG_TX | EVE_SPI_FLAG_BSWAP) : EVE_SPI_FLAG_BSWAP;
va_list argv;
uint16_t *p;
int i = 0;
va_start(argv, fmt);
- _cmd_begin(cmd);
+ cmd_begin(cmd);
while (fmt[i]) {
switch (fmt[i]) {
case 'b':
eve_spi_xchg8(va_arg(argv, int), flags);
- _cmd_inc(1);
+ cmd_inc(1);
break;
case 'h':
eve_spi_xchg16(va_arg(argv, int), flags);
- _cmd_inc(2);
+ cmd_inc(2);
break;
case 'w':
eve_spi_xchg32(va_arg(argv, int), flags);
- _cmd_inc(4);
+ cmd_inc(4);
break;
case '&':
p = va_arg(argv, uint16_t *);
- *p = _cmd_offset;
+ *p = cmd_offset;
eve_spi_xchg32(0, flags);
- _cmd_inc(4);
+ cmd_inc(4);
break;
case 's':
- _cmd_string(va_arg(argv, const char *), flags);
+ cmd_string(va_arg(argv, const char *), flags);
break;
case 'p':
- _cmd_buffer(va_arg(argv, const char *), va_arg(argv, int), flags);
+ cmd_buffer(va_arg(argv, const char *), va_arg(argv, int), flags);
break;
}
i++;
}
va_end(argv);
/* padding */
- i = _cmd_offset & 3; /* equivalent to _cmd_offset % 4 */
+ i = cmd_offset & 3; /* equivalent to cmd_offset % 4 */
if (i) {
i = 4 - i; /* 3, 2 or 1 */
- _cmd_inc(i);
+ cmd_inc(i);
while (i > 0) {
eve_spi_xchg8(0, flags);
i--;
}
}
- _cmd_end();
+ cmd_end();
}
uint32_t eve_cmd_result(uint16_t offset) {
@@ -236,14 +236,14 @@ uint32_t eve_cmd_result(uint16_t offset) {
}
void eve_cmd_dl(uint32_t dl) {
- _cmd_begin(dl);
- _cmd_end();
+ cmd_begin(dl);
+ cmd_end();
}
int eve_cmd_done(void) {
uint16_t r = eve_read16(REG_CMD_READ);
if (r == 0xfff) {
- _cmd_offset = 0;
+ cmd_offset = 0;
eve_write8(REG_CPURESET, 1);
eve_write16(REG_CMD_READ, 0);
eve_write16(REG_CMD_WRITE, 0);
@@ -251,11 +251,11 @@ int eve_cmd_done(void) {
eve_write8(REG_CPURESET, 0);
return -1;
}
- return (r == _cmd_offset);
+ return (r == cmd_offset);
}
int eve_cmd_exec(int w) {
- eve_write16(REG_CMD_WRITE, _cmd_offset);
+ eve_write16(REG_CMD_WRITE, cmd_offset);
if (w) {
int r;
do {
@@ -267,46 +267,46 @@ int eve_cmd_exec(int w) {
}
void eve_cmd_burst_start(void) {
- uint32_t addr = EVE_RAM_CMD + _cmd_offset;
+ uint32_t addr = EVE_RAM_CMD + cmd_offset;
eve_spi_lock();
eve_spi_cs_set();
eve_spi_xchg24(addr | EVE_MEM_WRITE, EVE_SPI_FLAG_TX);
- _cmd_burst = 1;
+ cmd_burst = 1;
}
void eve_cmd_burst_end(void) {
eve_spi_flush();
eve_spi_cs_clear();
eve_spi_unlock();
- _cmd_burst = 0;
+ cmd_burst = 0;
}
void eve_active(void) {
eve_command(EVE_ACTIVE, 0);
- if (_power_state == EVE_PSTATE_SLEEP) eve_time_sleep(40);
+ if (power_state == EVE_PSTATE_SLEEP) eve_time_sleep(40);
- eve_write8(REG_PWM_DUTY, _brigtness);
- if (_power_state != EVE_PSTATE_SLEEP) return;
+ eve_write8(REG_PWM_DUTY, brigtness);
+ if (power_state != EVE_PSTATE_SLEEP) return;
eve_write8(REG_TOUCH_MODE, EVE_TMODE_CONTINUOUS);
eve_write8(REG_CTOUCH_EXTENDED, 0x00);
- _power_state = EVE_PSTATE_ACTIVE;
+ power_state = EVE_PSTATE_ACTIVE;
}
void eve_standby(void) {
- if (_power_state != EVE_PSTATE_ACTIVE) return;
+ if (power_state != EVE_PSTATE_ACTIVE) return;
- _brigtness = eve_read8(REG_PWM_DUTY);
+ brigtness = eve_read8(REG_PWM_DUTY);
eve_command(EVE_STANDBY, 0);
- _power_state = EVE_PSTATE_STANDBY;
+ power_state = EVE_PSTATE_STANDBY;
}
void eve_sleep(void) {
- if (_power_state != EVE_PSTATE_ACTIVE) return;
+ if (power_state != EVE_PSTATE_ACTIVE) return;
- _brigtness = eve_read8(REG_PWM_DUTY);
+ brigtness = eve_read8(REG_PWM_DUTY);
eve_write8(REG_PWM_DUTY, 0x0);
eve_write8(REG_CTOUCH_EXTENDED, 0x01);
@@ -315,7 +315,7 @@ void eve_sleep(void) {
eve_time_sleep(500);
eve_command(EVE_SLEEP, 0);
- _power_state = EVE_PSTATE_SLEEP;
+ power_state = EVE_PSTATE_SLEEP;
}
void eve_brightness(uint8_t b) {
@@ -323,7 +323,7 @@ void eve_brightness(uint8_t b) {
}
void eve_set_touch_calibration(uint32_t *matrix) {
- _touch_calib = matrix;
+ touch_calib = matrix;
}
static int _init(void) {
@@ -382,13 +382,13 @@ static int _init(void) {
eve_write8(REG_TOUCH_MODE, EVE_TMODE_CONTINUOUS); /* enable touch */
eve_write16(REG_TOUCH_RZTHRESH, EVE_TOUCH_RZTHRESH); /* eliminate any false touches */
- if (_touch_calib) {
- eve_write32(REG_TOUCH_TRANSFORM_A, _touch_calib[0]);
- eve_write32(REG_TOUCH_TRANSFORM_B, _touch_calib[1]);
- eve_write32(REG_TOUCH_TRANSFORM_C, _touch_calib[2]);
- eve_write32(REG_TOUCH_TRANSFORM_D, _touch_calib[3]);
- eve_write32(REG_TOUCH_TRANSFORM_E, _touch_calib[4]);
- eve_write32(REG_TOUCH_TRANSFORM_F, _touch_calib[5]);
+ if (touch_calib) {
+ eve_write32(REG_TOUCH_TRANSFORM_A, touch_calib[0]);
+ eve_write32(REG_TOUCH_TRANSFORM_B, touch_calib[1]);
+ eve_write32(REG_TOUCH_TRANSFORM_C, touch_calib[2]);
+ eve_write32(REG_TOUCH_TRANSFORM_D, touch_calib[3]);
+ eve_write32(REG_TOUCH_TRANSFORM_E, touch_calib[4]);
+ eve_write32(REG_TOUCH_TRANSFORM_F, touch_calib[5]);
} else {
uint32_t touch_calib[6];
eve_cmd_dl(CMD_DLSTART);
@@ -427,7 +427,7 @@ int eve_init(int pwr_on) {
int rv = _init();
if (rv) return rv;
} else {
- _power_state = EVE_PSTATE_SLEEP;
+ power_state = EVE_PSTATE_SLEEP;
eve_active();
}
diff --git a/fw/fe310/eos/eve/eve_platform.c b/fw/fe310/eos/eve/eve_platform.c
index cfaf6d5..6bc87bb 100644
--- a/fw/fe310/eos/eve/eve_platform.c
+++ b/fw/fe310/eos/eve/eve_platform.c
@@ -5,10 +5,10 @@
#include "eos.h"
#include "interrupt.h"
#include "event.h"
+
#include "eve.h"
#include "eve_platform.h"
-#include "irq_def.h"
static void handle_time(unsigned char type) {
eve_handle_time();
@@ -55,15 +55,15 @@ void eve_platform_init(void) {
GPIO_REG(GPIO_LOW_IE) |= (1 << EVE_PIN_INTR);
eos_intr_set(INT_GPIO_BASE + EVE_PIN_INTR, IRQ_PRIORITY_UI, handle_intr);
- eos_spi_dev_set_div(EOS_DEV_DISP, 4);
+ eos_spi_set_div(EOS_SPI_DEV_EVE, 4);
}
void eve_spi_start(void) {
- eos_spi_dev_select(EOS_DEV_DISP);
+ eos_spi_select(EOS_SPI_DEV_EVE);
}
void eve_spi_stop(void) {
- eos_spi_dev_deselect();
+ eos_spi_deselect();
}
#include <stdio.h>
diff --git a/fw/fe310/eos/eve/eve_touch.c b/fw/fe310/eos/eve/eve_touch.c
index f777093..e75cf4e 100644
--- a/fw/fe310/eos/eve/eve_touch.c
+++ b/fw/fe310/eos/eve/eve_touch.c
@@ -4,16 +4,16 @@
#include "eve.h"
-static int _intr_mask = EVE_INT_TAG | EVE_INT_TOUCH;
-static int _multitouch;
-static uint8_t _tag0;
+static int touch_intr_mask = EVE_INT_TAG | EVE_INT_TOUCH;
+static int touch_multi;
+static uint8_t touch_tag0;
-static EVETouch _touch[EVE_MAX_TOUCH];
-static EVETouchTimer _touch_timer;
+static EVETouch touch_obj[EVE_MAX_TOUCH];
+static EVETouchTimer touch_timer;
-static eve_touch_handler_t _touch_handler;
-static void *_touch_handler_param;
-static uint8_t _tag_opt[256];
+static eve_touch_handler_t touch_handler;
+static void *touch_handler_param;
+static uint8_t touch_tag_opt[256];
static const uint32_t _reg_touch[] = {
REG_CTOUCH_TOUCH0_XY,
@@ -46,14 +46,14 @@ void eve_handle_touch(void) {
eve_spi_start();
- flags = eve_read8(REG_INT_FLAGS) & _intr_mask;
- if (!_multitouch && (flags & EVE_INT_TOUCH)) _multitouch = 1;
+ flags = eve_read8(REG_INT_FLAGS) & touch_intr_mask;
+ if (!touch_multi && (flags & EVE_INT_TOUCH)) touch_multi = 1;
for (i=0; i<EVE_MAX_TOUCH; i++) {
uint8_t touch_tag;
uint32_t touch_xy;
uint64_t now = 0;
uint16_t touch_evt = 0;
- EVETouch *touch = &_touch[i];
+ EVETouch *touch = &touch_obj[i];
touch_xy = i < 4 ? eve_read32(_reg_touch[i]) : (((uint32_t)eve_read16(REG_CTOUCH_TOUCH4_X) << 16) | eve_read16(REG_CTOUCH_TOUCH4_Y));
@@ -95,8 +95,8 @@ void eve_handle_touch(void) {
}
eve_touch_timer_clear(touch);
- if (_touch_handler && touch_evt) {
- _touch_handler(_touch_timer.touch, touch_evt, _touch_timer.tag0, _touch_handler_param);
+ if (touch_handler && touch_evt) {
+ touch_handler(touch_timer.touch, touch_evt, touch_timer.tag0, touch_handler_param);
}
}
touch_evt = EVE_TOUCH_ETYPE_POINT | _evt;
@@ -122,7 +122,7 @@ void eve_handle_touch(void) {
}
touch->x = touch_x;
touch->y = touch_y;
- if (_multitouch || (flags & EVE_INT_TAG)) {
+ if (touch_multi || (flags & EVE_INT_TAG)) {
touch_tag = eve_read8(_reg_tag[i]);
} else {
touch_tag = touch->tag;
@@ -139,13 +139,13 @@ void eve_handle_touch(void) {
eve_touch_timer_set_evt(touch, _ttevt & ~EVE_TOUCH_ETYPE_LPRESS);
}
if (touch->tracker.tag && touch->tracker.track) {
- uint8_t opt = _tag_opt[touch->tracker.tag];
+ uint8_t opt = touch_tag_opt[touch->tracker.tag];
char track_ext = ((opt & EVE_TOUCH_OPT_TRACK_EXT_X) && (touch->eevt & EVE_TOUCH_EETYPE_TRACK_X)) ||
((opt & EVE_TOUCH_OPT_TRACK_EXT_Y) && (touch->eevt & EVE_TOUCH_EETYPE_TRACK_Y));
if (!eve_touch_timer_get_evt(NULL) && track_ext) {
EVEVTrack *vtrack = eve_vtrack_get();
- eve_touch_timer_set(touch, EVE_TOUCH_ETYPE_TRACK, _tag0, EVE_TOUCH_TIMEOUT_TRACK);
+ eve_touch_timer_set(touch, EVE_TOUCH_ETYPE_TRACK, touch_tag0, EVE_TOUCH_TIMEOUT_TRACK);
if (vtrack->start) vtrack->start(touch, vtrack->param);
} else {
touch_evt |= EVE_TOUCH_ETYPE_TRACK_STOP;
@@ -155,23 +155,23 @@ void eve_handle_touch(void) {
}
if (touch_tag != touch->tag) {
if (touch_tag) {
- if (!_tag0) _tag0 = touch_tag;
+ if (!touch_tag0) touch_tag0 = touch_tag;
if (!touch->tag0) {
touch->tag0 = touch_tag;
- if (_tag_opt[touch_tag] & (EVE_TOUCH_OPT_TRACK | EVE_TOUCH_OPT_TRACK_REG)) {
+ if (touch_tag_opt[touch_tag] & (EVE_TOUCH_OPT_TRACK | EVE_TOUCH_OPT_TRACK_REG)) {
touch->tracker.tag = touch_tag;
}
- if (touch->tracker.tag && !(_tag_opt[touch->tracker.tag] & EVE_TOUCH_OPT_TRACK_XY)) {
+ if (touch->tracker.tag && !(touch_tag_opt[touch->tracker.tag] & EVE_TOUCH_OPT_TRACK_XY)) {
touch_evt |= EVE_TOUCH_ETYPE_TRACK_START;
touch->tracker.track = 1;
touch->t = now;
}
- if (!eve_touch_timer_get_evt(NULL) && (_tag_opt[touch_tag] & (EVE_TOUCH_OPT_LPRESS | EVE_TOUCH_OPT_TAP2))) {
+ if (!eve_touch_timer_get_evt(NULL) && (touch_tag_opt[touch_tag] & (EVE_TOUCH_OPT_LPRESS | EVE_TOUCH_OPT_TAP2))) {
uint16_t _evt = 0;
- if (_tag_opt[touch_tag] & EVE_TOUCH_OPT_LPRESS) _evt |= EVE_TOUCH_ETYPE_LPRESS;
- if (_tag_opt[touch_tag] & EVE_TOUCH_OPT_TAP2) _evt |= EVE_TOUCH_ETYPE_TAP2;
- eve_touch_timer_set(touch, _evt, _tag0, EVE_TOUCH_TIMEOUT_TAP);
+ if (touch_tag_opt[touch_tag] & EVE_TOUCH_OPT_LPRESS) _evt |= EVE_TOUCH_ETYPE_LPRESS;
+ if (touch_tag_opt[touch_tag] & EVE_TOUCH_OPT_TAP2) _evt |= EVE_TOUCH_ETYPE_TAP2;
+ eve_touch_timer_set(touch, _evt, touch_tag0, EVE_TOUCH_TIMEOUT_TAP);
}
}
}
@@ -190,10 +190,10 @@ void eve_handle_touch(void) {
dx = dx < 0 ? -dx : dx;
dy = dy < 0 ? -dy : dy;
if (_track) {
- if ((dx > EVE_TOUCH_THRESHOLD_X) && !(_tag_opt[touch->tracker.tag] & EVE_TOUCH_OPT_TRACK_X)) {
+ if ((dx > EVE_TOUCH_THRESHOLD_X) && !(touch_tag_opt[touch->tracker.tag] & EVE_TOUCH_OPT_TRACK_X)) {
touch->tracker.tag = 0;
}
- if ((dy > EVE_TOUCH_THRESHOLD_Y) && !(_tag_opt[touch->tracker.tag] & EVE_TOUCH_OPT_TRACK_Y)) {
+ if ((dy > EVE_TOUCH_THRESHOLD_Y) && !(touch_tag_opt[touch->tracker.tag] & EVE_TOUCH_OPT_TRACK_Y)) {
touch->tracker.tag = 0;
}
if (touch->tracker.tag && ((dx > EVE_TOUCH_THRESHOLD_X) || (dy > EVE_TOUCH_THRESHOLD_Y))) {
@@ -214,8 +214,8 @@ void eve_handle_touch(void) {
}
}
if (touch->tracker.tag && touch->tracker.track) {
- if (_tag_opt[touch->tracker.tag] & EVE_TOUCH_OPT_TRACK) touch_evt |= EVE_TOUCH_ETYPE_TRACK;
- if (_tag_opt[touch->tracker.tag] & EVE_TOUCH_OPT_TRACK_REG) touch_evt |= EVE_TOUCH_ETYPE_TRACK_REG;
+ if (touch_tag_opt[touch->tracker.tag] & EVE_TOUCH_OPT_TRACK) touch_evt |= EVE_TOUCH_ETYPE_TRACK;
+ if (touch_tag_opt[touch->tracker.tag] & EVE_TOUCH_OPT_TRACK_REG) touch_evt |= EVE_TOUCH_ETYPE_TRACK_REG;
}
if (touch_evt & EVE_TOUCH_ETYPE_TRACK_REG) {
uint32_t touch_track = eve_read32(_reg_track[i]);
@@ -227,48 +227,48 @@ void eve_handle_touch(void) {
}
if (touch->tracker.tag || _timer) int_ccomplete = 1;
}
- if (_touch_handler && touch_evt) {
- _touch_handler(touch, touch_evt, _tag0, _touch_handler_param);
+ if (touch_handler && touch_evt) {
+ touch_handler(touch, touch_evt, touch_tag0, touch_handler_param);
}
- if (!_multitouch) break;
+ if (!touch_multi) break;
}
if (!touch_ex) {
- _tag0 = 0;
- _multitouch = 0;
+ touch_tag0 = 0;
+ touch_multi = 0;
}
- if (_multitouch) int_ccomplete = 1;
+ if (touch_multi) int_ccomplete = 1;
- if (int_ccomplete && !(_intr_mask & EVE_INT_CONVCOMPLETE)) {
- _intr_mask |= EVE_INT_CONVCOMPLETE;
- eve_write8(REG_INT_MASK, _intr_mask);
+ if (int_ccomplete && !(touch_intr_mask & EVE_INT_CONVCOMPLETE)) {
+ touch_intr_mask |= EVE_INT_CONVCOMPLETE;
+ eve_write8(REG_INT_MASK, touch_intr_mask);
}
- if (!int_ccomplete && (_intr_mask & EVE_INT_CONVCOMPLETE)) {
- _intr_mask &= ~EVE_INT_CONVCOMPLETE;
- eve_write8(REG_INT_MASK, _intr_mask);
+ if (!int_ccomplete && (touch_intr_mask & EVE_INT_CONVCOMPLETE)) {
+ touch_intr_mask &= ~EVE_INT_CONVCOMPLETE;
+ eve_write8(REG_INT_MASK, touch_intr_mask);
}
eve_spi_stop();
}
void eve_handle_time(void) {
- EVETouch *touch = _touch_timer.touch;
+ EVETouch *touch = touch_timer.touch;
- if (_touch_timer.evt) {
+ if (touch_timer.evt) {
int more = 0;
uint16_t touch_evt = 0;
eve_spi_start();
- if (_touch_timer.evt & EVE_TOUCH_ETYPE_LPRESS) {
+ if (touch_timer.evt & EVE_TOUCH_ETYPE_LPRESS) {
touch_evt |= EVE_TOUCH_ETYPE_LPRESS;
if (touch) touch->eevt |= EVE_TOUCH_EETYPE_LPRESS;
}
- if (_touch_timer.evt & EVE_TOUCH_ETYPE_TAP2) {
+ if (touch_timer.evt & EVE_TOUCH_ETYPE_TAP2) {
touch_evt |= EVE_TOUCH_ETYPE_TAP1;
}
- if (_touch_timer.evt & EVE_TOUCH_ETYPE_TRACK) {
+ if (touch_timer.evt & EVE_TOUCH_ETYPE_TRACK) {
EVEVTrack *vtrack = eve_vtrack_get();
if (vtrack->tick) {
@@ -280,19 +280,19 @@ void eve_handle_time(void) {
if (vtrack->stop) vtrack->stop(touch, vtrack->param);
}
}
- if (_touch_timer.evt & EVE_TOUCH_ETYPE_TIMER) {
+ if (touch_timer.evt & EVE_TOUCH_ETYPE_TIMER) {
touch_evt |= EVE_TOUCH_ETYPE_TIMER;
more = 1;
}
if (more) {
- eve_timer_set(_touch_timer.to);
+ eve_timer_set(touch_timer.to);
} else {
- _touch_timer.evt = 0;
+ touch_timer.evt = 0;
}
- if (_touch_handler && touch_evt) {
- _touch_handler(touch, touch_evt, _touch_timer.tag0, _touch_handler_param);
+ if (touch_handler && touch_evt) {
+ touch_handler(touch, touch_evt, touch_timer.tag0, touch_handler_param);
}
eve_spi_stop();
@@ -305,27 +305,27 @@ void eve_touch_init(void) {
eve_vtrack_init();
for (i=0; i<EVE_MAX_TOUCH; i++) {
- EVETouch *touch = &_touch[i];
+ EVETouch *touch = &touch_obj[i];
touch->eevt |= EVE_TOUCH_EETYPE_NOTOUCH;
}
- eve_write8(REG_INT_MASK, _intr_mask);
+ eve_write8(REG_INT_MASK, touch_intr_mask);
eve_write8(REG_INT_EN, 0x01);
while(eve_read8(REG_INT_FLAGS));
}
void eve_touch_set_handler(eve_touch_handler_t handler, void *param) {
- _touch_handler = handler;
- _touch_handler_param = param;
+ touch_handler = handler;
+ touch_handler_param = param;
}
EVETouch *eve_touch_get(int i) {
- return &_touch[i];
+ return &touch_obj[i];
}
int8_t eve_touch_get_idx(EVETouch *touch) {
if (touch == NULL) return -1;
- return touch - _touch;
+ return touch - touch_obj;
}
uint16_t eve_touch_evt(EVETouch *touch, uint16_t evt, uint8_t tag0, uint8_t tag_min, uint8_t tag_n) {
@@ -363,22 +363,22 @@ uint16_t eve_touch_evt(EVETouch *touch, uint16_t evt, uint8_t tag0, uint8_t tag_
}
void eve_touch_set_opt(uint8_t tag, uint8_t opt) {
- _tag_opt[tag] = opt;
+ touch_tag_opt[tag] = opt;
}
uint8_t eve_touch_get_opt(uint8_t tag) {
- return _tag_opt[tag];
+ return touch_tag_opt[tag];
}
void eve_touch_clear_opt(void) {
- memset(_tag_opt, 0, sizeof(_tag_opt));
+ memset(touch_tag_opt, 0, sizeof(touch_tag_opt));
}
void eve_touch_timer_set(EVETouch *touch, uint16_t evt, uint8_t tag0, uint32_t to) {
- _touch_timer.touch = touch;
- _touch_timer.evt = evt;
- _touch_timer.tag0 = tag0;
- _touch_timer.to = to;
+ touch_timer.touch = touch;
+ touch_timer.evt = evt;
+ touch_timer.tag0 = tag0;
+ touch_timer.to = to;
eve_timer_set(to);
}
@@ -389,21 +389,21 @@ void eve_touch_timer_clear(EVETouch *touch) {
uint16_t eve_touch_timer_get_evt(EVETouch *touch) {
uint16_t ret = 0;
- if ((touch == NULL) || (_touch_timer.touch == touch)) {
- ret = _touch_timer.evt;
- } else if (_touch_timer.touch == NULL) {
- ret = _touch_timer.evt & EVE_TOUCH_ETYPE_TIMER;
+ if ((touch == NULL) || (touch_timer.touch == touch)) {
+ ret = touch_timer.evt;
+ } else if (touch_timer.touch == NULL) {
+ ret = touch_timer.evt & EVE_TOUCH_ETYPE_TIMER;
}
return ret;
}
void eve_touch_timer_set_evt(EVETouch *touch, uint16_t evt) {
- if (touch == _touch_timer.touch) {
- _touch_timer.evt = evt;
- } else if (_touch_timer.touch == NULL) {
- _touch_timer.evt = evt & EVE_TOUCH_ETYPE_TIMER;
+ if (touch == touch_timer.touch) {
+ touch_timer.evt = evt;
+ } else if (touch_timer.touch == NULL) {
+ touch_timer.evt = evt & EVE_TOUCH_ETYPE_TIMER;
}
- if (!_touch_timer.evt) eve_timer_clear();
+ if (!touch_timer.evt) eve_timer_clear();
}
void eve_touch_timer_start(uint8_t tag0, uint32_t to) {
@@ -415,5 +415,5 @@ void eve_touch_timer_stop(void) {
}
EVETouchTimer *eve_touch_timer_get(void) {
- return &_touch_timer;
+ return &touch_timer;
}
diff --git a/fw/fe310/eos/eve/eve_vtrack.c b/fw/fe310/eos/eve/eve_vtrack.c
index dfa8ba8..b9f28af 100644
--- a/fw/fe310/eos/eve/eve_vtrack.c
+++ b/fw/fe310/eos/eve/eve_vtrack.c
@@ -3,32 +3,32 @@
#include "eve.h"
-static EVEVTrack _vtrack;
-static EVEPhyAcc _vtrack_acc;
+static EVEVTrack vtrack;
+static EVEPhyAcc vtrack_acc;
void eve_vtrack_init(void) {
- eve_phy_acc_init(&_vtrack_acc, -EVE_VTRACK_ACC_A);
+ eve_phy_acc_init(&vtrack_acc, -EVE_VTRACK_ACC_A);
eve_vtrack_reset();
}
EVEVTrack *eve_vtrack_get(void) {
- return &_vtrack;
+ return &vtrack;
}
void eve_vtrack_set(eve_vtrack_start_t start, eve_vtrack_tick_t tick, eve_vtrack_stop_t stop, void *param) {
- _vtrack.start = start;
- _vtrack.tick = tick;
- _vtrack.stop = stop;
- _vtrack.param = param;
+ vtrack.start = start;
+ vtrack.tick = tick;
+ vtrack.stop = stop;
+ vtrack.param = param;
}
void eve_vtrack_reset(void) {
- eve_vtrack_set(eve_vtrack_acc_start, eve_vtrack_acc_tick, NULL, &_vtrack_acc);
+ eve_vtrack_set(eve_vtrack_acc_start, eve_vtrack_acc_tick, NULL, &vtrack_acc);
}
void eve_vtrack_start(EVETouch *touch, uint8_t tag0, uint32_t to) {
eve_touch_timer_set(touch, EVE_TOUCH_ETYPE_TRACK, tag0, to);
- if (_vtrack.start) _vtrack.start(touch, _vtrack.param);
+ if (vtrack.start) vtrack.start(touch, vtrack.param);
}
void eve_vtrack_stop(EVETouch *touch) {
diff --git a/fw/fe310/eos/eve/screen/window.c b/fw/fe310/eos/eve/screen/window.c
index 4f059c4..63a59a9 100644
--- a/fw/fe310/eos/eve/screen/window.c
+++ b/fw/fe310/eos/eve/screen/window.c
@@ -68,7 +68,7 @@ int eve_window_visible(EVEWindow *window) {
return 1;
}
-static void _window_visible_g(EVEWindow *w, EVERect *g) {
+static void window_visible_g(EVEWindow *w, EVERect *g) {
while (w) {
if (eve_window_visible(w)) {
if (w->g.x > g->x) g->w = MIN(g->w, w->g.x - g->x);
@@ -84,15 +84,15 @@ static void _window_visible_g(EVEWindow *w, EVERect *g) {
g->h -= y0;
}
}
- if (w->child_head) _window_visible_g(w->child_head, g);
+ if (w->child_head) window_visible_g(w->child_head, g);
w = w->next;
}
}
void eve_window_visible_g(EVEWindow *window, EVERect *g) {
*g = window->g;
- if (window->child_head) _window_visible_g(window->child_head, g);
- _window_visible_g(window->next, g);
+ if (window->child_head) window_visible_g(window->child_head, g);
+ window_visible_g(window->next, g);
}
void eve_window_append(EVEWindow *window) {
diff --git a/fw/fe310/eos/eve/widget/selectw.c b/fw/fe310/eos/eve/widget/selectw.c
index 7873e95..46ed3d1 100644
--- a/fw/fe310/eos/eve/widget/selectw.c
+++ b/fw/fe310/eos/eve/widget/selectw.c
@@ -16,7 +16,7 @@
#define DIVC(x,y) ((x) / (y) + ((x) % (y) != 0))
-static int _selectw_verify(utf8_t *option, uint16_t option_size) {
+static int selectw_verify(utf8_t *option, uint16_t option_size) {
int o_len;
uint16_t o_curr;
int rv;
@@ -32,7 +32,7 @@ static int _selectw_verify(utf8_t *option, uint16_t option_size) {
return EVE_OK;
}
-static int _selectw_count(EVESelectWidget *widget) {
+static int selectw_count(EVESelectWidget *widget) {
int o_len;
int o_curr;
int i;
@@ -51,7 +51,7 @@ static int _selectw_count(EVESelectWidget *widget) {
return i;
}
-static void _selectw_update_sz(EVESelectWidget *widget, int uievt) {
+static void selectw_update_sz(EVESelectWidget *widget, int uievt) {
EVEWidget *_widget = &widget->w;
EVEPage *page = _widget->page;
@@ -81,12 +81,12 @@ void eve_selectw_init(EVESelectWidget *widget, EVERect *g, EVEPage *page, EVEFon
memset(widget, 0, sizeof(EVESelectWidget));
eve_widget_init(_widget, EVE_WIDGET_TYPE_SELECT, g, page, eve_selectw_draw, eve_selectw_touch, NULL);
widget->font = font;
- rv = _selectw_verify(option, option_size);
+ rv = selectw_verify(option, option_size);
if (rv == EVE_OK) {
widget->option = option;
widget->option_size = option_size;
- widget->option_count = _selectw_count(widget);
- _selectw_update_sz(widget, 0);
+ widget->option_count = selectw_count(widget);
+ selectw_update_sz(widget, 0);
}
widget->multi = multi;
widget->select = widget->multi ? 0 : SELECTW_NOSELECT;
@@ -226,7 +226,7 @@ int eve_selectw_option_add(EVESelectWidget *widget, utf8_t *option) {
strcpy(widget->option + o_curr, option);
widget->option_count = i + 1;
- _selectw_update_sz(widget, 1);
+ selectw_update_sz(widget, 1);
return EVE_OK;
}
@@ -234,15 +234,15 @@ int eve_selectw_option_add(EVESelectWidget *widget, utf8_t *option) {
int eve_selectw_option_set(EVESelectWidget *widget, utf8_t *option, uint16_t option_size) {
int rv, i;
- rv = _selectw_verify(option, option_size);
+ rv = selectw_verify(option, option_size);
if (rv) return rv;
if (option_size > widget->option_size) return EVE_ERR_FULL;
memcpy(widget->option, option, option_size);
memset(widget->option + option_size, 0, widget->option_size - option_size);
- widget->option_count = _selectw_count(widget);
- _selectw_update_sz(widget, 1);
+ widget->option_count = selectw_count(widget);
+ selectw_update_sz(widget, 1);
return EVE_OK;
}
diff --git a/fw/fe310/eos/eve/widget/strw.c b/fw/fe310/eos/eve/widget/strw.c
index b169adb..232e52c 100644
--- a/fw/fe310/eos/eve/widget/strw.c
+++ b/fw/fe310/eos/eve/widget/strw.c
@@ -90,7 +90,7 @@ static EVEStrCursor *cursor_prox(EVEStrWidget *widget, EVEStrCursor *cursor, EVE
return NULL;
}
-static void _draw_str(EVEStrWidget *widget, uint16_t ch, uint16_t len, uint16_t x1, uint16_t x2, char s) {
+static void draw_string(EVEStrWidget *widget, uint16_t ch, uint16_t len, uint16_t x1, uint16_t x2, char s) {
int16_t x;
EVEWidget *_widget = &widget->w;
EVEPage *page = _widget->page;
@@ -116,7 +116,7 @@ static void _draw_str(EVEStrWidget *widget, uint16_t ch, uint16_t len, uint16_t
}
}
-static void _draw_cursor(EVEStrWidget *widget, EVEStrCursor *cursor) {
+static void draw_cursor(EVEStrWidget *widget, EVEStrCursor *cursor) {
uint16_t x, y;
EVEWidget *_widget = &widget->w;
@@ -187,12 +187,12 @@ uint8_t eve_strw_draw(EVEWidget *_widget, uint8_t tag0) {
l1 = c1->ch;
l2 = c2->ch - c1->ch;
l3 = widget->str_len - c2->ch;
- _draw_str(widget, 0, l1, 0, c1->x, 0);
- _draw_str(widget, c1->ch, l2, c1->x, c2->x, 1);
- _draw_str(widget, c2->ch, l3, c2->x, widget->str_g.x + _widget->g.w, 0);
+ draw_string(widget, 0, l1, 0, c1->x, 0);
+ draw_string(widget, c1->ch, l2, c1->x, c2->x, 1);
+ draw_string(widget, c2->ch, l3, c2->x, widget->str_g.x + _widget->g.w, 0);
} else {
- if (widget->cursor1.on) _draw_cursor(widget, &widget->cursor1);
- _draw_str(widget, 0, widget->str_len, 0, widget->str_g.x + _widget->g.w, 0);
+ if (widget->cursor1.on) draw_cursor(widget, &widget->cursor1);
+ draw_string(widget, 0, widget->str_len, 0, widget->str_g.x + _widget->g.w, 0);
}
if (cut) {
diff --git a/fw/fe310/eos/eve/widget/textw.c b/fw/fe310/eos/eve/widget/textw.c
index abf2a68..e994c0e 100644
--- a/fw/fe310/eos/eve/widget/textw.c
+++ b/fw/fe310/eos/eve/widget/textw.c
@@ -107,7 +107,7 @@ static EVETextCursor *cursor_prox(EVETextWidget *widget, EVETextCursor *cursor,
return NULL;
}
-static void _draw_line(EVETextWidget *widget, uint16_t l, uint16_t ch, uint16_t len, uint16_t x1, uint16_t x2, char s) {
+static void draw_line(EVETextWidget *widget, uint16_t l, uint16_t ch, uint16_t len, uint16_t x1, uint16_t x2, char s) {
EVEWidget *_widget = &widget->w;
EVEPage *page = _widget->page;
@@ -131,7 +131,7 @@ static void _draw_line(EVETextWidget *widget, uint16_t l, uint16_t ch, uint16_t
}
}
-static void _draw_cursor(EVETextWidget *widget, EVETextCursor *cursor) {
+static void draw_cursor(EVETextWidget *widget, EVETextCursor *cursor) {
uint16_t x, y;
EVEWidget *_widget = &widget->w;
@@ -198,10 +198,10 @@ uint8_t eve_textw_draw(EVEWidget *_widget, uint8_t tag0) {
l3 = 0;
s = 1;
}
- _draw_line(widget, i, LINE_START(widget, i), l1, 0, c1->x, 0);
- _draw_line(widget, i, c1->ch, l2, c1->x, s ? _widget->g.w : c2->x, 1);
+ draw_line(widget, i, LINE_START(widget, i), l1, 0, c1->x, 0);
+ draw_line(widget, i, c1->ch, l2, c1->x, s ? _widget->g.w : c2->x, 1);
if (!s) {
- _draw_line(widget, i, c2->ch, l3, c2->x, _widget->g.w, 0);
+ draw_line(widget, i, c2->ch, l3, c2->x, _widget->g.w, 0);
c1 = NULL;
c2 = NULL;
}
@@ -209,14 +209,14 @@ uint8_t eve_textw_draw(EVEWidget *_widget, uint8_t tag0) {
int l1 = c2->ch - LINE_START(widget, i);
int l2 = LINE_START(widget, i) + LINE_LEN(widget, i) - c2->ch;
- _draw_line(widget, i, LINE_START(widget, i), l1, 0, c2->x, 1);
- _draw_line(widget, i, c2->ch, l2, c2->x, _widget->g.w, 0);
+ draw_line(widget, i, LINE_START(widget, i), l1, 0, c2->x, 1);
+ draw_line(widget, i, c2->ch, l2, c2->x, _widget->g.w, 0);
c1 = NULL;
c2 = NULL;
s = 0;
} else {
- if (widget->cursor1.on && (widget->cursor1.line == i)) _draw_cursor(widget, &widget->cursor1);
- _draw_line(widget, i, LINE_START(widget, i), LINE_LEN(widget, i), 0, _widget->g.w, s);
+ if (widget->cursor1.on && (widget->cursor1.line == i)) draw_cursor(widget, &widget->cursor1);
+ draw_line(widget, i, LINE_START(widget, i), LINE_LEN(widget, i), 0, _widget->g.w, s);
}
}
if (lineNvisible) {
@@ -225,7 +225,7 @@ uint8_t eve_textw_draw(EVEWidget *_widget, uint8_t tag0) {
eve_touch_set_opt(_widget->tagN, TEXTW_TOUCH_OPT);
_widget->tagN++;
}
- _draw_line(widget, lineN, 0, 0, 0, _widget->g.w, 0);
+ draw_line(widget, lineN, 0, 0, 0, _widget->g.w, 0);
}
} else {
widget->line0 = 0;
diff --git a/fw/fe310/eos/i2s.c b/fw/fe310/eos/i2s.c
index c8216ff..b4fd277 100644
--- a/fw/fe310/eos/i2s.c
+++ b/fw/fe310/eos/i2s.c
@@ -9,13 +9,14 @@
#include "interrupt.h"
#include "event.h"
+#include "board.h"
+
#include "i2s.h"
-#include "i2s_def.h"
-#include "irq_def.h"
+#include "i2s_priv.h"
-#define I2S_PWM_REG_CK PWM0_REG
-#define I2S_PWM_REG_WS_MIC PWM1_REG
-#define I2S_PWM_REG_WS_SPK PWM2_REG
+#define I2S_REG_CK(o) _REG32(I2S_CTRL_ADDR_CK, o)
+#define I2S_REG_WS_MIC(o) _REG32(I2S_CTRL_ADDR_WS_MIC, o)
+#define I2S_REG_WS_SPK(o) _REG32(I2S_CTRL_ADDR_WS_SPK, o)
#define MIN(X, Y) (((X) < (Y)) ? (X) : (Y))
#define MAX(X, Y) (((X) > (Y)) ? (X) : (Y))
@@ -112,22 +113,22 @@ static void i2s_handle_evt(unsigned char type, unsigned char *buffer, uint16_t l
}
static void _mic_vol_set(uint8_t vol) {
- I2S_PWM_REG_WS_MIC(PWM_CMP2) = i2s_clk_period * (vol + 1);
- I2S_PWM_REG_WS_MIC(PWM_CMP3) = I2S_PWM_REG_WS_MIC(PWM_CMP2) + i2s_clk_period * 16;
+ I2S_REG_WS_MIC(PWM_CMP2) = i2s_clk_period * (vol + 1);
+ I2S_REG_WS_MIC(PWM_CMP3) = I2S_REG_WS_MIC(PWM_CMP2) + i2s_clk_period * 16;
}
static void _spk_vol_set(uint8_t vol) {
int spk_cmp = vol + i2s_mic_volume - 16;
if (spk_cmp <= 0) {
- I2S_PWM_REG_WS_SPK(PWM_CMP1) = i2s_clk_period * (32 + spk_cmp);
- I2S_PWM_REG_WS_SPK(PWM_CMP2) = i2s_clk_period * (64 + spk_cmp);
- I2S_PWM_REG_WS_SPK(PWM_CMP3) = i2s_clk_period * 33;
+ I2S_REG_WS_SPK(PWM_CMP1) = i2s_clk_period * (32 + spk_cmp);
+ I2S_REG_WS_SPK(PWM_CMP2) = i2s_clk_period * (64 + spk_cmp);
+ I2S_REG_WS_SPK(PWM_CMP3) = i2s_clk_period * 33;
GPIO_REG(GPIO_OUTPUT_XOR) &= ~(1 << I2S_PIN_WS_SPK);
} else {
- I2S_PWM_REG_WS_SPK(PWM_CMP1) = i2s_clk_period * spk_cmp;
- I2S_PWM_REG_WS_SPK(PWM_CMP2) = i2s_clk_period * (32 + spk_cmp);
- I2S_PWM_REG_WS_SPK(PWM_CMP3) = i2s_clk_period * (33 + spk_cmp);
+ I2S_REG_WS_SPK(PWM_CMP1) = i2s_clk_period * spk_cmp;
+ I2S_REG_WS_SPK(PWM_CMP2) = i2s_clk_period * (32 + spk_cmp);
+ I2S_REG_WS_SPK(PWM_CMP3) = i2s_clk_period * (33 + spk_cmp);
GPIO_REG(GPIO_OUTPUT_XOR) |= (1 << I2S_PIN_WS_SPK);
}
}
@@ -179,21 +180,21 @@ void eos_i2s_init(void) {
void eos_i2s_start(uint32_t sample_rate, unsigned char fmt) {
i2s_clk_period = ((PRCI_get_cpu_freq() / (sample_rate * 64)) & ~I2S_PWM_SCALE_CK_MASK) + 1;
- I2S_PWM_REG_CK(PWM_CMP0) = i2s_clk_period >> I2S_PWM_SCALE_CK;
- I2S_PWM_REG_CK(PWM_CMP1) = I2S_PWM_REG_CK(PWM_CMP0) / 2;
- I2S_PWM_REG_CK(PWM_CMP2) = 0;
- I2S_PWM_REG_CK(PWM_CMP3) = 0;
+ I2S_REG_CK(PWM_CMP0) = i2s_clk_period >> I2S_PWM_SCALE_CK;
+ I2S_REG_CK(PWM_CMP1) = I2S_REG_CK(PWM_CMP0) / 2;
+ I2S_REG_CK(PWM_CMP2) = 0;
+ I2S_REG_CK(PWM_CMP3) = 0;
- I2S_PWM_REG_WS_MIC(PWM_CMP0) = i2s_clk_period * 64 - 1;
- I2S_PWM_REG_WS_MIC(PWM_CMP1) = i2s_clk_period * 32;
+ I2S_REG_WS_MIC(PWM_CMP0) = i2s_clk_period * 64 - 1;
+ I2S_REG_WS_MIC(PWM_CMP1) = i2s_clk_period * 32;
_mic_vol_set(i2s_mic_volume);
- I2S_PWM_REG_WS_SPK(PWM_CMP0) = i2s_clk_period * 64 - 1;
+ I2S_REG_WS_SPK(PWM_CMP0) = i2s_clk_period * 64 - 1;
_spk_vol_set(i2s_spk_volume);
- I2S_PWM_REG_CK(PWM_COUNT) = 0;
- I2S_PWM_REG_WS_MIC(PWM_COUNT) = 0;
- I2S_PWM_REG_WS_SPK(PWM_COUNT) = i2s_clk_period / 2;
+ I2S_REG_CK(PWM_COUNT) = 0;
+ I2S_REG_WS_MIC(PWM_COUNT) = 0;
+ I2S_REG_WS_SPK(PWM_COUNT) = i2s_clk_period / 2;
_eos_i2s_fmt = fmt;
_eos_i2s_mic_evt_enable = 1;
@@ -206,9 +207,9 @@ void eos_i2s_start(uint32_t sample_rate, unsigned char fmt) {
_eos_i2s_start_pwm();
/*
- I2S_PWM_REG_CK(PWM_CFG) = PWM_CFG_ENALWAYS | PWM_CFG_ZEROCMP | I2S_PWM_SCALE_CK;
- I2S_PWM_REG_WS_MIC(PWM_CFG) = PWM_CFG_ENALWAYS | PWM_CFG_ZEROCMP | PWM_CFG_CMP2GANG;
- I2S_PWM_REG_WS_SPK(PWM_CFG) = PWM_CFG_ENALWAYS | PWM_CFG_ZEROCMP | PWM_CFG_CMP1GANG;
+ I2S_REG_CK(PWM_CFG) = PWM_CFG_ENALWAYS | PWM_CFG_ZEROCMP | I2S_PWM_SCALE_CK;
+ I2S_REG_WS_MIC(PWM_CFG) = PWM_CFG_ENALWAYS | PWM_CFG_ZEROCMP | PWM_CFG_CMP2GANG;
+ I2S_REG_WS_SPK(PWM_CFG) = PWM_CFG_ENALWAYS | PWM_CFG_ZEROCMP | PWM_CFG_CMP1GANG;
*/
GPIO_REG(GPIO_INPUT_EN) |= (1 << I2S_PIN_SD_IN);
@@ -228,12 +229,12 @@ void eos_i2s_start(uint32_t sample_rate, unsigned char fmt) {
}
void eos_i2s_stop(void) {
- I2S_PWM_REG_CK(PWM_CFG) = 0;
- I2S_PWM_REG_WS_MIC(PWM_CFG) = 0;
- I2S_PWM_REG_WS_SPK(PWM_CFG) = 0;
- I2S_PWM_REG_CK(PWM_COUNT) = 0;
- I2S_PWM_REG_WS_MIC(PWM_COUNT) = 0;
- I2S_PWM_REG_WS_SPK(PWM_COUNT) = 0;
+ I2S_REG_CK(PWM_CFG) = 0;
+ I2S_REG_WS_MIC(PWM_CFG) = 0;
+ I2S_REG_WS_SPK(PWM_CFG) = 0;
+ I2S_REG_CK(PWM_COUNT) = 0;
+ I2S_REG_WS_MIC(PWM_COUNT) = 0;
+ I2S_REG_WS_SPK(PWM_COUNT) = 0;
_eos_i2s_mic_evt_enable = 0;
_eos_i2s_spk_evt_enable = 0;
diff --git a/fw/fe310/eos/i2s.h b/fw/fe310/eos/i2s.h
index 744958e..47dc3e2 100644
--- a/fw/fe310/eos/i2s.h
+++ b/fw/fe310/eos/i2s.h
@@ -1,12 +1,6 @@
#include <stdint.h>
-#define EOS_I2S_FMT_ALAW 0
-#define EOS_I2S_FMT_PCM16 1
-
-/* should match i2s_def.h definitions */
-#define EOS_I2S_ETYPE_MIC 1
-#define EOS_I2S_ETYPE_SPK 2
-
+#include "i2s_def.h"
typedef struct EOSABuf {
uint16_t idx_r;
diff --git a/fw/fe310/eos/i2s_def.h b/fw/fe310/eos/i2s_def.h
index 3a09982..1af70bb 100644
--- a/fw/fe310/eos/i2s_def.h
+++ b/fw/fe310/eos/i2s_def.h
@@ -1,24 +1,5 @@
-#define I2S_ETYPE_MIC 1
-#define I2S_ETYPE_SPK 2
+#define EOS_I2S_FMT_ALAW 0
+#define EOS_I2S_FMT_PCM16 1
-#define I2S_PIN_CK 1 /* PWM 0.1 */
-#define I2S_PIN_CK_SW 21 /* PWM 1.2 */
-#define I2S_PIN_CK_SR 18
-#define I2S_PIN_WS_MIC 19 /* PWM 1.1 */
-#define I2S_PIN_WS_SPK 11 /* PWM 2.1 */
-#define I2S_PIN_SD_IN 13
-#define I2S_PIN_SD_OUT 12
-
-#define I2S_IRQ_WS_ID (INT_PWM2_BASE + 0)
-#define I2S_IRQ_SD_ID (INT_PWM2_BASE + 3)
-
-#define I2S_IDLE_CYCLES 8
-
-#define I2S_PWM_SCALE_CK 2
-#define I2S_PWM_SCALE_CK_MASK 0x0003
-
-/* asm */
-#define I2S_ABUF_OFF_IDXR 0
-#define I2S_ABUF_OFF_IDXW 2
-#define I2S_ABUF_OFF_SIZE 4
-#define I2S_ABUF_OFF_ARRAY 8
+#define EOS_I2S_ETYPE_MIC 1
+#define EOS_I2S_ETYPE_SPK 2
diff --git a/fw/fe310/eos/i2s_priv.h b/fw/fe310/eos/i2s_priv.h
new file mode 100644
index 0000000..25237c3
--- /dev/null
+++ b/fw/fe310/eos/i2s_priv.h
@@ -0,0 +1,8 @@
+#define I2S_PWM_SCALE_CK 2
+#define I2S_PWM_SCALE_CK_MASK 0x0003
+
+/* asm */
+#define I2S_ABUF_OFF_IDXR 0
+#define I2S_ABUF_OFF_IDXW 2
+#define I2S_ABUF_OFF_SIZE 4
+#define I2S_ABUF_OFF_ARRAY 8
diff --git a/fw/fe310/eos/interrupt.h b/fw/fe310/eos/interrupt.h
index 075e7eb..feaf277 100644
--- a/fw/fe310/eos/interrupt.h
+++ b/fw/fe310/eos/interrupt.h
@@ -1,5 +1,7 @@
#include <stdint.h>
+#include "irq_def.h"
+
typedef void (*eos_intr_handler_t) (void);
void eos_intr_init(void);
diff --git a/fw/fe310/eos/msgq_def.h b/fw/fe310/eos/msgq_priv.h
index 2ad5fc5..2ad5fc5 100644
--- a/fw/fe310/eos/msgq_def.h
+++ b/fw/fe310/eos/msgq_priv.h
diff --git a/fw/fe310/eos/net.c b/fw/fe310/eos/net.c
index eb5e6f2..c9bbc63 100644
--- a/fw/fe310/eos/net.c
+++ b/fw/fe310/eos/net.c
@@ -6,17 +6,25 @@
#include "eos.h"
#include "msgq.h"
-#include "event.h"
#include "interrupt.h"
+#include "event.h"
#include "timer.h"
#include "power.h"
+#include "board.h"
+
#include "spi.h"
-#include "spi_def.h"
+#include "spi_priv.h"
#include "net.h"
-#include "net_def.h"
-#include "irq_def.h"
+
+#define NET_STATE_FLAG_RUN 0x01
+#define NET_STATE_FLAG_RST 0x02
+#define NET_STATE_FLAG_RTS 0x04
+#define NET_STATE_FLAG_CTS 0x08
+#define NET_STATE_FLAG_INIT 0x10
+#define NET_STATE_FLAG_ONEW 0x20
+#define NET_STATE_FLAG_XCHG 0x40
#define MIN(X, Y) (((X) < (Y)) ? (X) : (Y))
#define MAX(X, Y) (((X) > (Y)) ? (X) : (Y))
@@ -312,8 +320,8 @@ void eos_net_init(void) {
void eos_net_start(void) {
eos_intr_set_handler(INT_SPI1_BASE, net_handle_xchg);
- SPI1_REG(SPI_REG_SCKDIV) = NET_SPI_DIV;
- SPI1_REG(SPI_REG_CSID) = NET_SPI_CSID;
+ SPI1_REG(SPI_REG_SCKDIV) = eos_spi_div(EOS_SPI_DEV_NET);
+ SPI1_REG(SPI_REG_CSID) = eos_spi_csid(EOS_SPI_DEV_NET);
clear_csr(mstatus, MSTATUS_MIE);
net_state_flags |= NET_STATE_FLAG_RUN;
@@ -396,8 +404,8 @@ int eos_net_wake(uint8_t source) {
if (rv) return rv;
eos_intr_set_handler(INT_SPI1_BASE, net_handle_xchg);
- SPI1_REG(SPI_REG_SCKDIV) = NET_SPI_DIV;
- SPI1_REG(SPI_REG_CSID) = NET_SPI_CSID;
+ SPI1_REG(SPI_REG_SCKDIV) = eos_spi_div(EOS_SPI_DEV_NET);
+ SPI1_REG(SPI_REG_CSID) = eos_spi_csid(EOS_SPI_DEV_NET);
clear_csr(mstatus, MSTATUS_MIE);
net_state_flags |= NET_STATE_FLAG_RUN;
@@ -494,7 +502,7 @@ int eos_net_send(unsigned char type, unsigned char *buffer, uint16_t len, unsign
set_csr(mstatus, MSTATUS_MIE);
spi_dev = eos_spi_dev();
- rv = eos_spi_dev_deselect();
+ rv = eos_spi_deselect();
if (rv) return rv;
clear_csr(mstatus, MSTATUS_MIE);
@@ -506,7 +514,7 @@ int eos_net_send(unsigned char type, unsigned char *buffer, uint16_t len, unsign
net_xchg_start(type, buffer, len);
set_csr(mstatus, MSTATUS_MIE);
- eos_spi_dev_select(spi_dev);
+ eos_spi_select(spi_dev);
} else {
if ((net_state_flags & NET_STATE_FLAG_RUN) && (net_state_flags & NET_STATE_FLAG_CTS)) {
net_xchg_start(type, buffer, len);
diff --git a/fw/fe310/eos/net_def.h b/fw/fe310/eos/net_def.h
deleted file mode 100644
index 9aa25dd..0000000
--- a/fw/fe310/eos/net_def.h
+++ /dev/null
@@ -1,13 +0,0 @@
-#define NET_PIN_RTS 20
-#define NET_PIN_CTS 22
-
-#define NET_STATE_FLAG_RUN 0x01
-#define NET_STATE_FLAG_RST 0x02
-#define NET_STATE_FLAG_RTS 0x04
-#define NET_STATE_FLAG_CTS 0x08
-#define NET_STATE_FLAG_INIT 0x10
-#define NET_STATE_FLAG_ONEW 0x20
-#define NET_STATE_FLAG_XCHG 0x40
-
-#define NET_SPI_DIV 16
-#define NET_SPI_CSID 3
diff --git a/fw/fe310/eos/power.c b/fw/fe310/eos/power.c
index 55960c9..6f292b8 100644
--- a/fw/fe310/eos/power.c
+++ b/fw/fe310/eos/power.c
@@ -74,9 +74,9 @@ uint8_t eos_power_reset_cause(void) {
}
void eos_power_sleep(void) {
- eos_spi_dev_select(EOS_DEV_DISP);
+ eos_spi_select(EOS_SPI_DEV_EVE);
eve_sleep();
- eos_spi_dev_deselect();
+ eos_spi_deselect();
eos_net_sleep(1000);
AON_REG(AON_PMUKEY) = 0x51F15E;
diff --git a/fw/fe310/eos/spi.c b/fw/fe310/eos/spi.c
index 29970bd..932c5f1 100644
--- a/fw/fe310/eos/spi.c
+++ b/fw/fe310/eos/spi.c
@@ -9,18 +9,19 @@
#include "interrupt.h"
#include "event.h"
+#include "board.h"
+
#include "net.h"
#include "spi.h"
-#include "spi_def.h"
-#include "irq_def.h"
+#include "spi_priv.h"
#define MIN(X, Y) (((X) < (Y)) ? (X) : (Y))
#define MAX(X, Y) (((X) > (Y)) ? (X) : (Y))
-#define SPI_IOF_MASK (((uint32_t)1 << IOF_SPI1_SCK) | ((uint32_t)1 << IOF_SPI1_MOSI) | ((uint32_t)1 << IOF_SPI1_MISO)) | ((uint32_t)1 << IOF_SPI1_SS0) | ((uint32_t)1 << IOF_SPI1_SS2) | ((uint32_t)1 << IOF_SPI1_SS3)
static uint8_t spi_dev;
-static uint8_t spi_dev_cs_pin;
+static uint8_t spi_cspin;
static uint8_t spi_lock;
+static uint16_t spi_div[EOS_SPI_MAX_DEV];
static volatile uint8_t spi_state_flags;
static unsigned char spi_in_xchg;
@@ -60,28 +61,45 @@ void eos_spi_init(void) {
// There is no way here to change the CS polarity.
// SPI1_REG(SPI_REG_CSDEF) = 0xFFFF;
+
+ for (i=0; i<EOS_SPI_MAX_DEV; i++) {
+ spi_div[i] = spi_cfg[i].div;
+ if (spi_cfg[i].csid == SPI_CSID_NONE) {
+ GPIO_REG(GPIO_INPUT_EN) &= ~(1 << spi_cfg[i].cspin);
+ GPIO_REG(GPIO_OUTPUT_EN) |= (1 << spi_cfg[i].cspin);
+ GPIO_REG(GPIO_PULLUP_EN) &= ~(1 << spi_cfg[i].cspin);
+ GPIO_REG(GPIO_OUTPUT_XOR) &= ~(1 << spi_cfg[i].cspin);
+ GPIO_REG(GPIO_OUTPUT_VAL) |= (1 << spi_cfg[i].cspin);
+ }
+ }
}
-int eos_spi_start(unsigned char dev, uint32_t div, uint32_t csid, uint8_t pin) {
- spi_dev = dev;
+int eos_spi_select(unsigned char dev) {
+ if (dev == EOS_SPI_DEV_NET) return EOS_ERR;
+ if (spi_dev != EOS_SPI_DEV_NET) return EOS_ERR;
+
+ eos_net_stop();
spi_state_flags = 0;
- SPI1_REG(SPI_REG_SCKDIV) = div;
- SPI1_REG(SPI_REG_CSID) = csid;
- if (csid != SPI_CSID_NONE) {
+ SPI1_REG(SPI_REG_SCKDIV) = spi_div[dev];
+ SPI1_REG(SPI_REG_CSID) = spi_cfg[dev].csid;
+ if (spi_cfg[dev].csid != SPI_CSID_NONE) {
SPI1_REG(SPI_REG_CSMODE) = SPI_CSMODE_AUTO;
} else {
SPI1_REG(SPI_REG_CSMODE) = SPI_CSMODE_OFF;
- spi_dev_cs_pin = pin;
+ spi_cspin = spi_cfg[dev].cspin;
}
eos_intr_set_handler(INT_SPI1_BASE, eos_spi_handle_xchg);
return EOS_OK;
}
-int eos_spi_stop(void) {
+int eos_spi_deselect(void) {
+ if (spi_dev == EOS_SPI_DEV_NET) return EOS_ERR;
if (spi_lock) return EOS_ERR_BUSY;
+
eos_spi_flush();
- spi_dev = 0;
+ eos_net_start();
+ spi_dev = EOS_SPI_DEV_NET;
return EOS_OK;
}
@@ -90,6 +108,18 @@ uint8_t eos_spi_dev(void) {
return spi_dev;
}
+uint16_t eos_spi_div(unsigned char dev) {
+ return spi_div[dev];
+}
+
+uint16_t eos_spi_csid(unsigned char dev) {
+ return spi_cfg[dev].csid;
+}
+
+uint16_t eos_spi_cspin(unsigned char dev) {
+ return spi_cfg[dev].cspin;
+}
+
void eos_spi_lock(void) {
spi_lock = 1;
}
@@ -98,6 +128,10 @@ void eos_spi_unlock(void) {
spi_lock = 0;
}
+void eos_spi_set_div(unsigned char dev, uint16_t div) {
+ spi_div[dev] = div;
+}
+
void eos_spi_set_handler(unsigned char dev, eos_evt_handler_t handler) {
if (handler == NULL) handler = eos_evtq_bad_handler;
if (dev && (dev <= EOS_SPI_MAX_DEV)) evt_handler[dev - 1] = handler;
@@ -127,7 +161,7 @@ static void spi_xchg_finish(void) {
void eos_spi_xchg(unsigned char *buffer, uint16_t len, uint8_t flags) {
if (spi_in_xchg) spi_xchg_finish();
- spi_in_xchg=1;
+ spi_in_xchg = 1;
_eos_spi_xchg_init(buffer, len, flags);
eos_spi_cs_set();
@@ -158,7 +192,7 @@ void eos_spi_handle_xchg(void) {
spi_state_flags &= ~SPI_FLAG_XCHG;
if (!(spi_state_flags & EOS_SPI_FLAG_MORE)) eos_spi_cs_clear();
SPI1_REG(SPI_REG_IE) = 0x0;
- if (spi_dev) eos_evtq_push_isr(EOS_EVT_SPI | spi_dev, spi_state_buf, spi_state_len);
+ if (spi_dev != EOS_SPI_DEV_NET) eos_evtq_push_isr(EOS_EVT_SPI | spi_dev, spi_state_buf, spi_state_len);
} else {
SPI1_REG(SPI_REG_RXCTRL) = SPI_RXWM(MIN(spi_state_len - spi_state_idx_rx - 1, SPI_SIZE_WM - 1));
SPI1_REG(SPI_REG_IE) = SPI_IP_RXWM;
@@ -169,7 +203,7 @@ void eos_spi_handle_xchg(void) {
void eos_spi_cs_set(void) {
/* cs low */
if (SPI1_REG(SPI_REG_CSMODE) == SPI_CSMODE_OFF) {
- GPIO_REG(GPIO_OUTPUT_VAL) &= ~(1 << spi_dev_cs_pin);
+ GPIO_REG(GPIO_OUTPUT_VAL) &= ~(1 << spi_cspin);
} else {
SPI1_REG(SPI_REG_CSMODE) = SPI_CSMODE_HOLD;
}
@@ -178,7 +212,7 @@ void eos_spi_cs_set(void) {
void eos_spi_cs_clear(void) {
/* cs high */
if (SPI1_REG(SPI_REG_CSMODE) == SPI_CSMODE_OFF) {
- GPIO_REG(GPIO_OUTPUT_VAL) |= (1 << spi_dev_cs_pin);
+ GPIO_REG(GPIO_OUTPUT_VAL) |= (1 << spi_cspin);
} else {
SPI1_REG(SPI_REG_CSMODE) = SPI_CSMODE_AUTO;
}
diff --git a/fw/fe310/eos/spi.h b/fw/fe310/eos/spi.h
index 7cbff08..ba04cc0 100644
--- a/fw/fe310/eos/spi.h
+++ b/fw/fe310/eos/spi.h
@@ -1,19 +1,29 @@
#include <stdint.h>
#include "event.h"
-#include "spi_dev.h"
-#define EOS_SPI_MAX_DEV EOS_DEV_MAX_DEV
+#define EOS_SPI_DEV_NET 0
+#define EOS_SPI_DEV_EVE 1
+#define EOS_SPI_DEV_SDC 2
+#define EOS_SPI_DEV_CAM 3
-#define EOS_SPI_FLAG_TX 0x01
-#define EOS_SPI_FLAG_MORE 0x02
-#define EOS_SPI_FLAG_BSWAP 0x04
+#define EOS_SPI_MAX_DEV 4
+
+#define EOS_SPI_FLAG_TX 0x01
+#define EOS_SPI_FLAG_MORE 0x02
+#define EOS_SPI_FLAG_BSWAP 0x04
void eos_spi_init(void);
-int eos_spi_start(unsigned char dev, uint32_t div, uint32_t csid, uint8_t pin);
-int eos_spi_stop(void);
+int eos_spi_select(unsigned char dev);
+int eos_spi_deselect(void);
+
uint8_t eos_spi_dev(void);
+uint16_t eos_spi_div(unsigned char dev);
+uint16_t eos_spi_csid(unsigned char dev);
+uint16_t eos_spi_cspin(unsigned char dev);
+
void eos_spi_lock(void);
void eos_spi_unlock(void);
+void eos_spi_set_div(unsigned char dev, uint16_t div);
void eos_spi_set_handler(unsigned char dev, eos_evt_handler_t handler);
void _eos_spi_xchg_init(unsigned char *buffer, uint16_t len, uint8_t flags);
diff --git a/fw/fe310/eos/spi_def.h b/fw/fe310/eos/spi_def.h
deleted file mode 100644
index 06f7251..0000000
--- a/fw/fe310/eos/spi_def.h
+++ /dev/null
@@ -1,12 +0,0 @@
-#define SPI_MODE0 0x00
-#define SPI_MODE1 0x01
-#define SPI_MODE2 0x02
-#define SPI_MODE3 0x03
-
-/* DO NOT TOUCH THEESE */
-#define SPI_SIZE_CHUNK 4
-#define SPI_SIZE_WM 2
-
-#define SPI_FLAG_XCHG 0x10
-
-#define SPI_CSID_NONE 1 \ No newline at end of file
diff --git a/fw/fe310/eos/spi_dev.c b/fw/fe310/eos/spi_dev.c
deleted file mode 100644
index 00b1a5b..0000000
--- a/fw/fe310/eos/spi_dev.c
+++ /dev/null
@@ -1,77 +0,0 @@
-#include <stdlib.h>
-#include <stdint.h>
-
-#include "encoding.h"
-#include "platform.h"
-
-#include "eos.h"
-#include "spi.h"
-#include "net.h"
-
-#include "spi_def.h"
-#include "spi_dev.h"
-
-
-#define SPI_DIV_DISP 16
-#define SPI_DIV_CARD 16
-#define SPI_DIV_CAM 16
-
-#define SPI_CSID_DISP 2
-#define SPI_CSID_CARD 0
-
-#define SPI_CSPIN_CAM 23
-
-static uint16_t spi_dev_div[EOS_DEV_MAX_DEV];
-
-int eos_spi_dev_select(unsigned char dev) {
- uint8_t spi_dev = eos_spi_dev();
- int rv = EOS_ERR;
-
- if (spi_dev) {
- int rv;
-
- rv = eos_spi_stop();
- if (rv) return rv;
- } else {
- eos_net_stop();
- }
- switch (dev) {
- case EOS_DEV_DISP:
- rv = eos_spi_start(dev, spi_dev_div[dev - 1], SPI_CSID_DISP, 0);
- break;
- case EOS_DEV_CARD:
- rv = eos_spi_start(dev, spi_dev_div[dev - 1], SPI_CSID_CARD, 0);
- break;
- case EOS_DEV_CAM:
- rv = eos_spi_start(dev, spi_dev_div[dev - 1], SPI_CSID_NONE, SPI_CSPIN_CAM);
- break;
- }
-
- return rv;
-}
-
-int eos_spi_dev_deselect(void) {
- int rv;
-
- rv = eos_spi_stop();
- if (rv) return rv;
- eos_net_start();
-
- return EOS_OK;
-}
-
-void eos_spi_dev_init(void) {
- spi_dev_div[EOS_DEV_DISP - 1] = SPI_DIV_DISP;
- spi_dev_div[EOS_DEV_CARD - 1] = SPI_DIV_CARD;
- spi_dev_div[EOS_DEV_CAM - 1] = SPI_DIV_CAM;
-
- GPIO_REG(GPIO_INPUT_EN) &= ~(1 << SPI_CSPIN_CAM);
- GPIO_REG(GPIO_OUTPUT_EN) |= (1 << SPI_CSPIN_CAM);
- GPIO_REG(GPIO_PULLUP_EN) &= ~(1 << SPI_CSPIN_CAM);
- GPIO_REG(GPIO_OUTPUT_XOR) &= ~(1 << SPI_CSPIN_CAM);
- GPIO_REG(GPIO_OUTPUT_VAL) |= (1 << SPI_CSPIN_CAM);
-}
-
-void eos_spi_dev_set_div(unsigned char dev, uint16_t div) {
- spi_dev_div[dev-1] = div;
-}
diff --git a/fw/fe310/eos/spi_dev.h b/fw/fe310/eos/spi_dev.h
deleted file mode 100644
index 7882e51..0000000
--- a/fw/fe310/eos/spi_dev.h
+++ /dev/null
@@ -1,11 +0,0 @@
-#define EOS_DEV_DISP 1
-#define EOS_DEV_CARD 2
-#define EOS_DEV_CAM 3
-
-#define EOS_DEV_MAX_DEV 3
-
-void eos_spi_dev_init(void);
-int eos_spi_dev_select(unsigned char dev);
-int eos_spi_dev_deselect(void);
-
-void eos_spi_dev_set_div(unsigned char dev, uint16_t div);
diff --git a/fw/fe310/eos/spi_priv.h b/fw/fe310/eos/spi_priv.h
new file mode 100644
index 0000000..a0344ff
--- /dev/null
+++ b/fw/fe310/eos/spi_priv.h
@@ -0,0 +1,44 @@
+#define SPI_MODE0 0x00
+#define SPI_MODE1 0x01
+#define SPI_MODE2 0x02
+#define SPI_MODE3 0x03
+
+/* DO NOT TOUCH THEESE */
+#define SPI_SIZE_CHUNK 4
+#define SPI_SIZE_WM 2
+
+#define SPI_FLAG_XCHG 0x10
+
+#define SPI_CSID_NONE 1
+#define SPI_CSPIN_NONE 0xff
+
+#define SPI_IOF_MASK (((uint32_t)1 << IOF_SPI1_SCK) | ((uint32_t)1 << IOF_SPI1_MOSI) | ((uint32_t)1 << IOF_SPI1_MISO)) | ((uint32_t)1 << IOF_SPI1_SS0) | ((uint32_t)1 << IOF_SPI1_SS2) | ((uint32_t)1 << IOF_SPI1_SS3)
+
+typedef struct {
+ uint8_t div;
+ uint8_t csid;
+ uint8_t cspin;
+} SPIConfig;
+
+static const SPIConfig spi_cfg[] = {
+ { // DEV_NET
+ .div = SPI_DIV_NET,
+ .csid = SPI_CSID_NET,
+ .cspin = SPI_CSPIN_NET,
+ },
+ { // DEV_EVE
+ .div = SPI_DIV_EVE,
+ .csid = SPI_CSID_EVE,
+ .cspin = SPI_CSPIN_EVE,
+ },
+ { // DEV_SDC
+ .div = SPI_DIV_SDC,
+ .csid = SPI_CSID_SDC,
+ .cspin = SPI_CSPIN_SDC,
+ },
+ { // DEV_CAM
+ .div = SPI_DIV_CAM,
+ .csid = SPI_CSID_CAM,
+ .cspin = SPI_CSPIN_CAM,
+ },
+}; \ No newline at end of file
diff --git a/fw/fe310/eos/trap_entry.S b/fw/fe310/eos/trap_entry.S
index c24236b..d54243f 100644
--- a/fw/fe310/eos/trap_entry.S
+++ b/fw/fe310/eos/trap_entry.S
@@ -21,30 +21,16 @@
#define SPI1_CTRL_ADDR 0x10024000
#include "sifive/devices/spi.h"
-#include "evt_def.h"
-#include "msgq_def.h"
-#include "i2s_def.h"
-
#define INT_PWM0_BASE 40
#define INT_PWM1_BASE 44
#define INT_PWM2_BASE 48
-#define I2S_PWM_CTRL_ADDR_CK PWM0_CTRL_ADDR
-#define I2S_PWM_CTRL_ADDR_WS_MIC PWM1_CTRL_ADDR
-#define I2S_PWM_CTRL_ADDR_WS_SPK PWM2_CTRL_ADDR
-
-#define IOF_SPI1_SS0 2
-#define IOF_SPI1_SS1 8
-#define IOF_SPI1_SS2 9
-#define IOF_SPI1_SS3 10
-
-#define INT_SPI1_BASE 6
-#define INT_GPIO_BASE 8
-
-#include "net_def.h"
-#include "spi_def.h"
+#include "board.h"
#include "irq_def.h"
-
+#include "evt_def.h"
+#include "i2s_def.h"
+#include "i2s_priv.h"
+#include "msgq_priv.h"
.section .data.entry
.align 4
@@ -99,7 +85,7 @@ evtq_push:
i2s_handle_sd:
# exit if too early
- li x18, I2S_PWM_CTRL_ADDR_WS_SPK
+ li x18, I2S_CTRL_ADDR_WS_SPK
lw x8, PWM_COUNT(x18)
lw x9, PWM_CMP3(x18)
bltu x8, x9, i2s_handle_sd_exit
@@ -156,7 +142,7 @@ i2s_abuf_pop:
# push to event queue
jal x22, evtq_push
beqz x21, i2s_decode
- li x18, (EOS_EVT_I2S | I2S_ETYPE_SPK)
+ li x18, (EOS_EVT_I2S | EOS_I2S_ETYPE_SPK)
sb x18, MSGQ_ITEM_OFF_TYPE(x21)
i2s_decode:
@@ -349,7 +335,7 @@ i2s_abuf_push:
# push to event queue
jal x22, evtq_push
beqz x21, i2s_handle_sd_exit
- li x18, (EOS_EVT_I2S | I2S_ETYPE_MIC)
+ li x18, (EOS_EVT_I2S | EOS_I2S_ETYPE_MIC)
sb x18, MSGQ_ITEM_OFF_TYPE(x21)
i2s_handle_sd_exit:
@@ -387,9 +373,9 @@ _eos_i2s_start_pwm:
STORE x22, 6*REGBYTES(sp)
STORE x23, 7*REGBYTES(sp)
- li x18, I2S_PWM_CTRL_ADDR_CK
- li x19, I2S_PWM_CTRL_ADDR_WS_MIC
- li x20, I2S_PWM_CTRL_ADDR_WS_SPK
+ li x18, I2S_CTRL_ADDR_CK
+ li x19, I2S_CTRL_ADDR_WS_MIC
+ li x20, I2S_CTRL_ADDR_WS_SPK
li x21, PWM_CFG_ENALWAYS | PWM_CFG_ZEROCMP | I2S_PWM_SCALE_CK
li x22, PWM_CFG_ENALWAYS | PWM_CFG_ZEROCMP | PWM_CFG_CMP2GANG
li x23, PWM_CFG_ENALWAYS | PWM_CFG_ZEROCMP | PWM_CFG_CMP1GANG
diff --git a/fw/fe310/eos/uart.c b/fw/fe310/eos/uart.c
index e9349a7..c10b6d5 100644
--- a/fw/fe310/eos/uart.c
+++ b/fw/fe310/eos/uart.c
@@ -10,7 +10,6 @@
#include "event.h"
#include "uart.h"
-#include "irq_def.h"
static eos_uart_handler_t uart_handler[EOS_UART_MAX_ETYPE];