summaryrefslogtreecommitdiff
path: root/fw/fe310/eos
diff options
context:
space:
mode:
authorUros Majstorovic <majstor@majstor.org>2021-11-25 01:59:07 +0100
committerUros Majstorovic <majstor@majstor.org>2021-11-25 01:59:07 +0100
commit6a31936e80ae2743376dcbf9d39cd92461c4deca (patch)
treef6dedd2cbf3aee9bb8135c7a4ff874c066a6d072 /fw/fe310/eos
parentc44897fda572cf8837b4535a6d1aaad4605c14af (diff)
i2s init/start/running fixed; i2c start returns error if i2s is running
Diffstat (limited to 'fw/fe310/eos')
-rw-r--r--fw/fe310/eos/board.h8
-rw-r--r--fw/fe310/eos/eos.c2
-rwxr-xr-xfw/fe310/eos/eve/eve_config.h1
-rw-r--r--fw/fe310/eos/eve/eve_platform.c8
-rw-r--r--fw/fe310/eos/i2c.c13
-rw-r--r--fw/fe310/eos/i2c.h3
-rw-r--r--fw/fe310/eos/i2c/bq25895.c32
-rw-r--r--fw/fe310/eos/i2s.c51
-rw-r--r--fw/fe310/eos/i2s.h1
-rw-r--r--fw/fe310/eos/i2s_def.h4
-rw-r--r--fw/fe310/eos/spi_cfg.h4
-rw-r--r--fw/fe310/eos/spi_dev.h3
-rw-r--r--fw/fe310/eos/trap_entry.S8
13 files changed, 65 insertions, 73 deletions
diff --git a/fw/fe310/eos/board.h b/fw/fe310/eos/board.h
index 611751b..b92d500 100644
--- a/fw/fe310/eos/board.h
+++ b/fw/fe310/eos/board.h
@@ -1,6 +1,5 @@
#define SPI_DIV_NET 16
#define SPI_DIV_EVE 4
-#define SPI_DIV_EVE_SLOW 16
#define SPI_DIV_SDC 1024
#define SPI_DIV_CAM 24
@@ -14,7 +13,7 @@
#define SPI_CSPIN_SDC 0
#define SPI_CSPIN_CAM SPI_CSPIN_NONE
-#define SPI_IOF_MASK_CS (((uint32_t)1 << IOF_SPI1_SS0) | ((uint32_t)1 << IOF_SPI1_SS3))
+#define SPI_IOF_MASK_CS (((uint32_t)1 << IOF_SPI1_SS0) | ((uint32_t)1 << IOF_SPI1_SS2) | ((uint32_t)1 << IOF_SPI1_SS3))
#define NET_PIN_RTS 20
#define NET_PIN_CTS 22
@@ -41,5 +40,6 @@
#define EVE_GPIO_DIR 0xf
#define EVE_GPIO_CAM 0
-#define EVE_GPIO_EXT 1
-#define EVE_GPIO_MOTOR 3
+#define EVE_GPIO_DISP_EN 1
+#define EVE_GPIO_GAIN_SEL 2
+#define EVE_GPIO_HAPT 3
diff --git a/fw/fe310/eos/eos.c b/fw/fe310/eos/eos.c
index e394862..96fc298 100644
--- a/fw/fe310/eos/eos.c
+++ b/fw/fe310/eos/eos.c
@@ -5,6 +5,7 @@
#include "timer.h"
#include "power.h"
#include "i2s.h"
+#include "i2c.h"
#include "uart.h"
#include "spi.h"
#include "spi_dev.h"
@@ -32,6 +33,7 @@ void eos_init(void) {
eos_intr_init(wakeup_cause);
eos_timer_init(wakeup_cause);
eos_i2s_init(wakeup_cause);
+ eos_i2c_init(wakeup_cause);
eos_uart_init(wakeup_cause);
eos_spi_init(wakeup_cause);
eos_spi_dev_init(wakeup_cause);
diff --git a/fw/fe310/eos/eve/eve_config.h b/fw/fe310/eos/eve/eve_config.h
index 6b9b0a6..b0dd1a4 100755
--- a/fw/fe310/eos/eve/eve_config.h
+++ b/fw/fe310/eos/eve/eve_config.h
@@ -32,7 +32,6 @@
#define EVE_SWIZZLE (0L) /* Defines the arrangement of the RGB pins of the FT800 */
#define EVE_PCLK (1L) /* 60MHz / REG_PCLK = PCLK frequency - 30 MHz */
#define EVE_CSPREAD (0L) /* helps with noise, when set to 1 fewer signals are changed simultaneously, reset-default: 1 */
-#define EVE_TOUCH_RZTHRESH (1200L) /* touch-sensitivity */
#define EVE_GEN 4
diff --git a/fw/fe310/eos/eve/eve_platform.c b/fw/fe310/eos/eve/eve_platform.c
index 003f396..2a43f1c 100644
--- a/fw/fe310/eos/eve/eve_platform.c
+++ b/fw/fe310/eos/eve/eve_platform.c
@@ -66,14 +66,6 @@ void eve_spi_stop(void) {
eos_spi_deselect();
}
-void eve_spi_set_fast(void) {
- eos_spi_set_div(EOS_SPI_DEV_EVE, SPI_DIV_EVE);
-}
-
-void eve_spi_set_slow(void) {
- eos_spi_set_div(EOS_SPI_DEV_EVE, SPI_DIV_EVE_SLOW);
-}
-
#include <stdio.h>
void *eve_malloc(size_t size) {
diff --git a/fw/fe310/eos/i2c.c b/fw/fe310/eos/i2c.c
index 122a1b2..f296bc7 100644
--- a/fw/fe310/eos/i2c.c
+++ b/fw/fe310/eos/i2c.c
@@ -6,15 +6,24 @@
#include "prci_driver.h"
#include "eos.h"
+#include "i2s.h"
#include "i2c.h"
-void eos_i2c_start(uint32_t baud_rate) {
- eos_i2c_set_baud_rate(baud_rate);
+void eos_i2c_init(uint8_t wakeup_cause) {
GPIO_REG(GPIO_IOF_SEL) &= ~IOF0_I2C0_MASK;
+}
+
+int eos_i2c_start(uint32_t baud_rate) {
+ if (eos_i2s_running()) return EOS_ERR_BUSY;
+
+ eos_i2c_set_baud_rate(baud_rate);
GPIO_REG(GPIO_IOF_EN) |= IOF0_I2C0_MASK;
+
+ return EOS_OK;
}
void eos_i2c_stop(void) {
+ if (eos_i2s_running()) return;
GPIO_REG(GPIO_IOF_EN) &= ~IOF0_I2C0_MASK;
}
diff --git a/fw/fe310/eos/i2c.h b/fw/fe310/eos/i2c.h
index 9692ea0..260e680 100644
--- a/fw/fe310/eos/i2c.h
+++ b/fw/fe310/eos/i2c.h
@@ -1,6 +1,7 @@
#include <stdint.h>
-void eos_i2c_start(uint32_t baud_rate);
+void eos_i2c_init(uint8_t wakeup_cause);
+int eos_i2c_start(uint32_t baud_rate);
void eos_i2c_stop(void);
void eos_i2c_set_baud_rate(uint32_t baud_rate);
int eos_i2c_read(uint8_t addr, uint8_t reg, uint8_t *buffer, uint16_t len);
diff --git a/fw/fe310/eos/i2c/bq25895.c b/fw/fe310/eos/i2c/bq25895.c
index 85b162b..db4a6ab 100644
--- a/fw/fe310/eos/i2c/bq25895.c
+++ b/fw/fe310/eos/i2c/bq25895.c
@@ -9,27 +9,31 @@
void eos_bq25895_init(uint8_t wakeup_cause) {
int rst = (wakeup_cause == EOS_PWR_WAKE_RST);
- int i, ret = EOS_OK;
+ int i, rv = EOS_OK;
uint8_t data = 0;
- eos_i2c_start(100000);
+ rv = eos_i2c_start(100000);
+ if (rv) {
+ printf("I2C BUSY\n");
+ return;
+ }
if (rst) {
- ret = eos_i2c_write8(BQ25895_ADDR, 0x14, 0x80); // reset
- if (ret) printf("I2C ERROR 0x14\n");
- ret = eos_i2c_write8(BQ25895_ADDR, 0x14, 0x00); // disable watchdog
- if (ret) printf("I2C ERROR 0x14\n");
- ret = eos_i2c_write8(BQ25895_ADDR, 0x07, 0x8d); // disable watchdog
- if (ret) printf("I2C ERROR 0x07\n");
- ret = eos_i2c_write8(BQ25895_ADDR, 0x00, 0x28); // 2.1A input current
- if (ret) printf("I2C ERROR 0x00\n");
- ret = eos_i2c_write8(BQ25895_ADDR, 0x02, 0x30); // enable ICO, disaable MaxCharge and D+/D-
- if (ret) printf("I2C ERROR 0x02\n");
+ rv = eos_i2c_write8(BQ25895_ADDR, 0x14, 0x80); // reset
+ if (rv) printf("I2C ERROR 0x14\n");
+ rv = eos_i2c_write8(BQ25895_ADDR, 0x14, 0x00); // disable watchdog
+ if (rv) printf("I2C ERROR 0x14\n");
+ rv = eos_i2c_write8(BQ25895_ADDR, 0x07, 0x8d); // disable watchdog
+ if (rv) printf("I2C ERROR 0x07\n");
+ rv = eos_i2c_write8(BQ25895_ADDR, 0x00, 0x28); // 2.1A input current
+ if (rv) printf("I2C ERROR 0x00\n");
+ rv = eos_i2c_write8(BQ25895_ADDR, 0x02, 0x30); // enable ICO, disaable MaxCharge and D+/D-
+ if (rv) printf("I2C ERROR 0x02\n");
}
printf("BQ25895:\n");
for (i=0; i<0x15; i++) {
- ret = eos_i2c_read8(BQ25895_ADDR, i, &data);
- if (!ret) printf("REG%02x: %02x\n", i, data);
+ rv = eos_i2c_read8(BQ25895_ADDR, i, &data);
+ if (!rv) printf("REG%02x: %02x\n", i, data);
}
eos_i2c_stop();
}
diff --git a/fw/fe310/eos/i2s.c b/fw/fe310/eos/i2s.c
index f4d6b99..695967a 100644
--- a/fw/fe310/eos/i2s.c
+++ b/fw/fe310/eos/i2s.c
@@ -18,6 +18,8 @@
#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 I2S_PIN_PWM ((1 << I2S_PIN_CK) | (1 << I2S_PIN_CK_SW) | (1 << I2S_PIN_WS_MIC) | (1 << I2S_PIN_WS_SPK))
+
#define MIN(X, Y) (((X) < (Y)) ? (X) : (Y))
#define MAX(X, Y) (((X) > (Y)) ? (X) : (Y))
@@ -148,6 +150,11 @@ void eos_i2s_init(uint8_t wakeup_cause) {
GPIO_REG(GPIO_PULLUP_EN) &= ~(1 << I2S_PIN_CK_SW);
GPIO_REG(GPIO_OUTPUT_XOR) &= ~(1 << I2S_PIN_CK_SW);
+ GPIO_REG(GPIO_INPUT_EN) &= ~(1 << I2S_PIN_CK_SR);
+ GPIO_REG(GPIO_OUTPUT_EN) |= (1 << I2S_PIN_CK_SR);
+ GPIO_REG(GPIO_PULLUP_EN) &= ~(1 << I2S_PIN_CK_SR);
+ GPIO_REG(GPIO_OUTPUT_XOR) &= ~(1 << I2S_PIN_CK_SR);
+
GPIO_REG(GPIO_INPUT_EN) &= ~(1 << I2S_PIN_WS_MIC);
GPIO_REG(GPIO_OUTPUT_EN) |= (1 << I2S_PIN_WS_MIC);
GPIO_REG(GPIO_PULLUP_EN) &= ~(1 << I2S_PIN_WS_MIC);
@@ -158,12 +165,7 @@ void eos_i2s_init(uint8_t wakeup_cause) {
GPIO_REG(GPIO_PULLUP_EN) &= ~(1 << I2S_PIN_WS_SPK);
GPIO_REG(GPIO_OUTPUT_XOR) &= ~(1 << I2S_PIN_WS_SPK);
- GPIO_REG(GPIO_INPUT_EN) &= ~(1 << I2S_PIN_CK_SR);
- GPIO_REG(GPIO_OUTPUT_EN) |= (1 << I2S_PIN_CK_SR);
- GPIO_REG(GPIO_PULLUP_EN) &= ~(1 << I2S_PIN_CK_SR);
- GPIO_REG(GPIO_OUTPUT_XOR) &= ~(1 << I2S_PIN_CK_SR);
-
- GPIO_REG(GPIO_INPUT_EN) &= ~(1 << I2S_PIN_SD_IN);
+ GPIO_REG(GPIO_INPUT_EN) |= (1 << I2S_PIN_SD_IN);
GPIO_REG(GPIO_OUTPUT_EN) &= ~(1 << I2S_PIN_SD_IN);
GPIO_REG(GPIO_PULLUP_EN) &= ~(1 << I2S_PIN_SD_IN);
GPIO_REG(GPIO_OUTPUT_XOR) &= ~(1 << I2S_PIN_SD_IN);
@@ -173,6 +175,9 @@ void eos_i2s_init(uint8_t wakeup_cause) {
GPIO_REG(GPIO_PULLUP_EN) &= ~(1 << I2S_PIN_SD_OUT);
GPIO_REG(GPIO_OUTPUT_XOR) &= ~(1 << I2S_PIN_SD_OUT);
+ GPIO_REG(GPIO_IOF_EN) &= ~I2S_PIN_PWM;
+ GPIO_REG(GPIO_IOF_SEL) |= I2S_PIN_PWM;
+
GPIO_REG(GPIO_OUTPUT_VAL) |= (1 << I2S_PIN_CK_SW);
GPIO_REG(GPIO_OUTPUT_VAL) &= ~((1 << I2S_PIN_CK) | (1 << I2S_PIN_CK_SR) | (1 << I2S_PIN_WS_MIC) | (1 << I2S_PIN_WS_SPK));
}
@@ -212,20 +217,8 @@ void eos_i2s_start(uint32_t sample_rate, unsigned char fmt) {
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);
GPIO_REG(GPIO_OUTPUT_VAL) |= (1 << I2S_PIN_CK_SR);
-
- GPIO_REG(GPIO_IOF_SEL) |= (1 << I2S_PIN_CK);
- GPIO_REG(GPIO_IOF_EN) |= (1 << I2S_PIN_CK);
-
- GPIO_REG(GPIO_IOF_SEL) |= (1 << I2S_PIN_CK_SW);
- GPIO_REG(GPIO_IOF_EN) |= (1 << I2S_PIN_CK_SW);
-
- GPIO_REG(GPIO_IOF_SEL) |= (1 << I2S_PIN_WS_MIC);
- GPIO_REG(GPIO_IOF_EN) |= (1 << I2S_PIN_WS_MIC);
-
- GPIO_REG(GPIO_IOF_SEL) |= (1 << I2S_PIN_WS_SPK);
- GPIO_REG(GPIO_IOF_EN) |= (1 << I2S_PIN_WS_SPK);
+ GPIO_REG(GPIO_IOF_EN) |= I2S_PIN_PWM;
}
void eos_i2s_stop(void) {
@@ -243,22 +236,12 @@ void eos_i2s_stop(void) {
eos_intr_disable(I2S_IRQ_WS_ID);
eos_intr_disable(I2S_IRQ_SD_ID);
- GPIO_REG(GPIO_IOF_EN) &= ~(1 << I2S_PIN_CK);
- GPIO_REG(GPIO_IOF_SEL) &= ~(1 << I2S_PIN_CK);
-
- GPIO_REG(GPIO_IOF_EN) &= ~(1 << I2S_PIN_CK_SW);
- GPIO_REG(GPIO_IOF_SEL) &= ~(1 << I2S_PIN_CK_SW);
-
- GPIO_REG(GPIO_IOF_EN) &= ~(1 << I2S_PIN_WS_MIC);
- GPIO_REG(GPIO_IOF_SEL) &= ~(1 << I2S_PIN_WS_MIC);
-
- GPIO_REG(GPIO_IOF_EN) &= ~(1 << I2S_PIN_WS_SPK);
- GPIO_REG(GPIO_IOF_SEL) &= ~(1 << I2S_PIN_WS_SPK);
-
- GPIO_REG(GPIO_INPUT_EN) &= ~(1 << I2S_PIN_SD_IN);
+ GPIO_REG(GPIO_OUTPUT_VAL) &= ~(1 << I2S_PIN_CK_SR);
+ GPIO_REG(GPIO_IOF_EN) &= ~I2S_PIN_PWM;
+}
- GPIO_REG(GPIO_OUTPUT_VAL) |= (1 << I2S_PIN_CK_SW);
- GPIO_REG(GPIO_OUTPUT_VAL) &= ~((1 << I2S_PIN_CK) | (1 << I2S_PIN_CK_SR) | (1 << I2S_PIN_WS_MIC) | (1 << I2S_PIN_WS_SPK));
+int eos_i2s_running(void) {
+ return !!(GPIO_REG(GPIO_IOF_EN) & I2S_PIN_PWM);
}
void eos_i2s_mic_init(uint8_t *mic_arr, uint16_t mic_arr_size) {
diff --git a/fw/fe310/eos/i2s.h b/fw/fe310/eos/i2s.h
index c5a6c1a..1339d0f 100644
--- a/fw/fe310/eos/i2s.h
+++ b/fw/fe310/eos/i2s.h
@@ -14,6 +14,7 @@ typedef void (*eos_i2s_handler_t) (unsigned char);
void eos_i2s_init(uint8_t wakeup_cause);
void eos_i2s_start(uint32_t sample_rate, unsigned char fmt);
void eos_i2s_stop(void);
+int eos_i2s_running(void);
void eos_i2s_mic_init(uint8_t *mic_arr, uint16_t mic_arr_size);
void eos_i2s_mic_set_handler(eos_i2s_handler_t wm_handler);
void eos_i2s_mic_set_wm(uint16_t wm);
diff --git a/fw/fe310/eos/i2s_def.h b/fw/fe310/eos/i2s_def.h
index 1af70bb..a338828 100644
--- a/fw/fe310/eos/i2s_def.h
+++ b/fw/fe310/eos/i2s_def.h
@@ -1,5 +1,5 @@
-#define EOS_I2S_FMT_ALAW 0
-#define EOS_I2S_FMT_PCM16 1
+#define EOS_I2S_FMT_PCM16 0
+#define EOS_I2S_FMT_ALAW 1
#define EOS_I2S_ETYPE_MIC 1
#define EOS_I2S_ETYPE_SPK 2
diff --git a/fw/fe310/eos/spi_cfg.h b/fw/fe310/eos/spi_cfg.h
index 43b0763..84ab8bb 100644
--- a/fw/fe310/eos/spi_cfg.h
+++ b/fw/fe310/eos/spi_cfg.h
@@ -1,5 +1,7 @@
#include <stdint.h>
+#define EOS_SPI_MAX_DEV 4
+
typedef struct {
uint16_t div;
uint8_t csid;
@@ -7,7 +9,7 @@ typedef struct {
unsigned char evt;
} SPIConfig;
-static const SPIConfig spi_cfg[] = {
+static const SPIConfig spi_cfg[EOS_SPI_MAX_DEV] = {
{ // DEV_NET
.div = SPI_DIV_NET,
.csid = SPI_CSID_NET,
diff --git a/fw/fe310/eos/spi_dev.h b/fw/fe310/eos/spi_dev.h
index 2f56149..d5ddeb3 100644
--- a/fw/fe310/eos/spi_dev.h
+++ b/fw/fe310/eos/spi_dev.h
@@ -4,8 +4,7 @@
#define EOS_SPI_DEV_EVE 1
#define EOS_SPI_DEV_SDC 2
#define EOS_SPI_DEV_CAM 3
-
-#define EOS_SPI_MAX_DEV 4
+#define EOS_SPI_DEV_DISP 4
void eos_spi_dev_init(uint8_t wakeup_cause);
int eos_spi_select(unsigned char dev);
diff --git a/fw/fe310/eos/trap_entry.S b/fw/fe310/eos/trap_entry.S
index d54243f..055ae67 100644
--- a/fw/fe310/eos/trap_entry.S
+++ b/fw/fe310/eos/trap_entry.S
@@ -111,7 +111,7 @@ i2s_abuf_pop:
and x20, x20, x18
lw x21, I2S_ABUF_OFF_ARRAY(x9)
add x21, x21, x20
- bnez x23, 0f
+ beqz x23, 0f
lbu x8, 0(x21)
addi x18, x18, 1
j 1f
@@ -146,7 +146,7 @@ i2s_abuf_pop:
sb x18, MSGQ_ITEM_OFF_TYPE(x21)
i2s_decode:
- bnez x23, i2s_handle_sd_xchg
+ beqz x23, i2s_handle_sd_xchg
# aLaw decode -> x8
xori x8, x8, 0x55
andi x9, x8, 0x80
@@ -260,7 +260,7 @@ i2s_handle_sd_xchg:
lw x23, 0(x9)
i2s_encode:
- bnez x23, i2s_abuf_push
+ beqz x23, i2s_abuf_push
# aLaw encode -> x8
li x18, 0x800
li x19, 7
@@ -307,7 +307,7 @@ i2s_abuf_push:
and x20, x20, x19
lw x21, I2S_ABUF_OFF_ARRAY(x9)
add x21, x21, x20
- bnez x23, 0f
+ beqz x23, 0f
sb x8, 0(x21)
addi x19, x19, 1
addi x18, x18, 1