mirror of
https://gitee.com/beecue/fastbee.git
synced 2025-12-21 18:35:54 +08:00
更新硬件SDK
This commit is contained in:
@@ -0,0 +1,349 @@
|
||||
#ifndef __RTE_DEVICE_H
|
||||
#define __RTE_DEVICE_H
|
||||
|
||||
#include "ec618.h"
|
||||
|
||||
/* Peripheral IO Mode Select, Must Configure First !!!
|
||||
Note, when receiver works in DMA_MODE, interrupt is also enabled to transfer tailing bytes.
|
||||
*/
|
||||
|
||||
#define POLLING_MODE 0x1
|
||||
#define DMA_MODE 0x2
|
||||
#define IRQ_MODE 0x3
|
||||
#define UNILOG_MODE 0x4
|
||||
|
||||
#define RTE_UART0_TX_IO_MODE UNILOG_MODE
|
||||
#define RTE_UART0_RX_IO_MODE IRQ_MODE
|
||||
#define USART0_RX_TRIG_LVL (30)
|
||||
|
||||
#define RTE_UART1_TX_IO_MODE DMA_MODE
|
||||
#define RTE_UART1_RX_IO_MODE DMA_MODE
|
||||
|
||||
#define RTE_UART2_TX_IO_MODE POLLING_MODE
|
||||
#define RTE_UART2_RX_IO_MODE DMA_MODE
|
||||
|
||||
#define RTE_SPI0_IO_MODE POLLING_MODE
|
||||
|
||||
#define RTE_SPI1_IO_MODE POLLING_MODE
|
||||
|
||||
#define RTE_I2C0_IO_MODE POLLING_MODE
|
||||
#define RTE_I2C1_IO_MODE POLLING_MODE
|
||||
|
||||
|
||||
// I2C0 (Inter-integrated Circuit Interface) [Driver_I2C0]
|
||||
// Configuration settings for Driver_I2C0 in component ::Drivers:I2C
|
||||
#define RTE_I2C0 1
|
||||
|
||||
// { PAD_PIN28}, // 0 : gpio13 / 2 : I2C0 SCL
|
||||
// { PAD_PIN27}, // 0 : gpio12 / 2 : I2C0 SDA
|
||||
#define RTE_I2C0_SCL_BIT 28 // AUDIO use 28
|
||||
#define RTE_I2C0_SCL_FUNC PAD_MUX_ALT2
|
||||
|
||||
#define RTE_I2C0_SDA_BIT 27 // AUDIO use 27
|
||||
#define RTE_I2C0_SDA_FUNC PAD_MUX_ALT2
|
||||
|
||||
// DMA
|
||||
// Tx
|
||||
// Channel <0=>0 <1=>1 <2=>2 <3=>3 <4=>4 <5=>5 <6=>6 <7=>7
|
||||
#define RTE_I2C0_DMA_TX_EN 0
|
||||
#define RTE_I2C0_DMA_TX_REQID DMA_REQUEST_I2C0_TX
|
||||
// Rx
|
||||
// Channel <0=>0 <1=>1 <2=>2 <3=>3 <4=>4 <5=>5 <6=>6 <7=>7
|
||||
#define RTE_I2C0_DMA_RX_EN 0
|
||||
#define RTE_I2C0_DMA_RX_REQID DMA_REQUEST_I2C0_RX
|
||||
|
||||
// I2C1 (Inter-integrated Circuit Interface) [Driver_I2C1]
|
||||
// Configuration settings for Driver_I2C1 in component ::Drivers:I2C
|
||||
#define RTE_I2C1 1
|
||||
|
||||
// { PAD_PIN20}, // 0 : gpio5 / 2 : I2C1 SCL
|
||||
// { PAD_PIN19}, // 0 : gpio4 / 2 : I2C1 SDA
|
||||
#define RTE_I2C1_SCL_BIT 20
|
||||
#define RTE_I2C1_SCL_FUNC PAD_MUX_ALT2
|
||||
|
||||
#define RTE_I2C1_SDA_BIT 19
|
||||
#define RTE_I2C1_SDA_FUNC PAD_MUX_ALT2
|
||||
|
||||
// DMA
|
||||
// Tx
|
||||
// Channel <0=>0 <1=>1 <2=>2 <3=>3 <4=>4 <5=>5 <6=>6 <7=>7
|
||||
#define RTE_I2C1_DMA_TX_EN 1
|
||||
#define RTE_I2C1_DMA_TX_REQID DMA_REQUEST_I2C1_TX
|
||||
// Rx
|
||||
// Channel <0=>0 <1=>1 <2=>2 <3=>3 <4=>4 <5=>5 <6=>6 <7=>7
|
||||
#define RTE_I2C1_DMA_RX_EN 1
|
||||
#define RTE_I2C1_DMA_RX_REQID DMA_REQUEST_I2C1_RX
|
||||
|
||||
|
||||
// UART0 (Universal asynchronous receiver transmitter) [Driver_USART0]
|
||||
// Configuration settings for Driver_USART0 in component ::Drivers:USART
|
||||
#define RTE_UART0_CTS_PIN_EN 0
|
||||
#define RTE_UART0_RTS_PIN_EN 0
|
||||
|
||||
// { PAD_PIN27}, // 0 : gpio12 / 3 : UART0 RTSn
|
||||
// { PAD_PIN28}, // 0 : gpio13 / 3 : UART0 CTSn
|
||||
// { PAD_PIN29}, // 0 : gpio14 / 3 : UART0 RXD
|
||||
// { PAD_PIN30}, // 0 : gpio15 / 3 : UART0 TXD
|
||||
#define RTE_UART0_RTS_BIT 27
|
||||
#define RTE_UART0_RTS_FUNC PAD_MUX_ALT3
|
||||
|
||||
#define RTE_UART0_CTS_BIT 28
|
||||
#define RTE_UART0_CTS_FUNC PAD_MUX_ALT3
|
||||
|
||||
#define RTE_UART0_RX_BIT 29
|
||||
#define RTE_UART0_RX_FUNC PAD_MUX_ALT3
|
||||
|
||||
#define RTE_UART0_TX_BIT 30
|
||||
#define RTE_UART0_TX_FUNC PAD_MUX_ALT3
|
||||
|
||||
// DMA
|
||||
// Tx
|
||||
// Channel <0=>0 <1=>1 <2=>2 <3=>3 <4=>4 <5=>5 <6=>6 <7=>7
|
||||
#define RTE_UART0_DMA_TX_REQID DMA_REQUEST_USART0_TX
|
||||
// Rx
|
||||
// Channel <0=>0 <1=>1 <2=>2 <3=>3 <4=>4 <5=>5 <6=>6 <7=>7
|
||||
#define RTE_UART0_DMA_RX_REQID DMA_REQUEST_USART0_RX
|
||||
|
||||
// UART1 (Universal asynchronous receiver transmitter) [Driver_USART1]
|
||||
// Configuration settings for Driver_USART1 in component ::Drivers:USART
|
||||
#define RTE_UART1_CTS_PIN_EN 1
|
||||
#define RTE_UART1_RTS_PIN_EN 1
|
||||
|
||||
// { PAD_PIN31}, // 0 : gpio16 / 1 : UART1 RTS
|
||||
// { PAD_PIN32}, // 0 : gpio17 / 1 : UART1 CTS
|
||||
// { PAD_PIN33}, // 0 : gpio18 / 1 : UART1 RXD
|
||||
// { PAD_PIN34}, // 0 : gpio19 / 1 : UART1 TXD
|
||||
#define RTE_UART1_RTS_BIT 31
|
||||
#define RTE_UART1_RTS_FUNC PAD_MUX_ALT1
|
||||
|
||||
#define RTE_UART1_CTS_BIT 32
|
||||
#define RTE_UART1_CTS_FUNC PAD_MUX_ALT1
|
||||
|
||||
#define RTE_UART1_RX_BIT 33
|
||||
#define RTE_UART1_RX_FUNC PAD_MUX_ALT1
|
||||
|
||||
#define RTE_UART1_TX_BIT 34
|
||||
#define RTE_UART1_TX_FUNC PAD_MUX_ALT1
|
||||
|
||||
// DMA
|
||||
// Tx
|
||||
// Channel <0=>0 <1=>1 <2=>2 <3=>3 <4=>4 <5=>5 <6=>6 <7=>7
|
||||
#define RTE_UART1_DMA_TX_REQID DMA_REQUEST_USART1_TX
|
||||
// Rx
|
||||
// Channel <0=>0 <1=>1 <2=>2 <3=>3 <4=>4 <5=>5 <6=>6 <7=>7
|
||||
#define RTE_UART1_DMA_RX_REQID DMA_REQUEST_USART1_RX
|
||||
|
||||
// UART2 (Universal asynchronous receiver transmitter) [Driver_USART2]
|
||||
// Configuration settings for Driver_USART2 in component ::Drivers:USART
|
||||
#define RTE_UART2_CTS_PIN_EN 0
|
||||
#define RTE_UART2_RTS_PIN_EN 0
|
||||
|
||||
// { PAD_PIN25}, // 0 : gpio10 / 3 : UART2 RXD
|
||||
// { PAD_PIN26}, // 0 : gpio11 / 3 : UART2 TXD
|
||||
#define RTE_UART2_RX_BIT 25
|
||||
#define RTE_UART2_RX_FUNC PAD_MUX_ALT3
|
||||
|
||||
#define RTE_UART2_TX_BIT 26
|
||||
#define RTE_UART2_TX_FUNC PAD_MUX_ALT3
|
||||
|
||||
|
||||
// DMA
|
||||
// Tx
|
||||
// Channel <0=>0 <1=>1 <2=>2 <3=>3 <4=>4 <5=>5 <6=>6 <7=>7
|
||||
#define RTE_UART2_DMA_TX_REQID DMA_REQUEST_USART2_TX
|
||||
// Rx
|
||||
// Channel <0=>0 <1=>1 <2=>2 <3=>3 <4=>4 <5=>5 <6=>6 <7=>7
|
||||
#define RTE_UART2_DMA_RX_REQID DMA_REQUEST_USART2_RX
|
||||
|
||||
// SPI0 (Serial Peripheral Interface) [Driver_SPI0]
|
||||
// Configuration settings for Driver_SPI0 in component ::Drivers:SPI
|
||||
#define RTE_SPI0 1
|
||||
|
||||
// { PAD_PIN21}, // 0 : gpio16 / 1 : UART1 RTS / 2 : SPI0 SSn
|
||||
// { PAD_PIN22}, // 0 : gpio11 / 1 : UART1 CTS / 2 : SPI0 MOSI
|
||||
// { PAD_PIN23}, // 0 : gpio14 / 1 : UART1 RXD / 2 : SPI0 MISO
|
||||
// { PAD_PIN24}, // 0 : gpio15 / 1 : UART1 TXD / 2 : SPI0 SCLK
|
||||
#define RTE_SPI0_SSN_BIT 21
|
||||
#define RTE_SPI0_SSN_FUNC PAD_MUX_ALT2
|
||||
|
||||
#define RTE_SPI0_MOSI_BIT 22
|
||||
#define RTE_SPI0_MOSI_FUNC PAD_MUX_ALT2
|
||||
|
||||
#define RTE_SPI0_MISO_BIT 23
|
||||
#define RTE_SPI0_MISO_FUNC PAD_MUX_ALT2
|
||||
|
||||
#define RTE_SPI0_SCLK_BIT 24
|
||||
#define RTE_SPI0_SCLK_FUNC PAD_MUX_ALT2
|
||||
|
||||
#define RTE_SPI0_SSN_GPIO_INSTANCE 1
|
||||
#define RTE_SPI0_SSN_GPIO_INDEX 0
|
||||
|
||||
// DMA
|
||||
// Tx
|
||||
// Channel <0=>0 <1=>1 <2=>2 <3=>3 <4=>4 <5=>5 <6=>6 <7=>7
|
||||
#define RTE_SPI0_DMA_TX_REQID DMA_REQUEST_SPI0_TX
|
||||
|
||||
// Rx
|
||||
// Channel <0=>0 <1=>1 <2=>2 <3=>3 <4=>4 <5=>5 <6=>6 <7=>7
|
||||
#define RTE_SPI0_DMA_RX_REQID DMA_REQUEST_SPI0_RX
|
||||
|
||||
// SPI1 (Serial Peripheral Interface) [Driver_SPI1]
|
||||
// Configuration settings for Driver_SPI1 in component ::Drivers:SPI
|
||||
#define RTE_SPI1 1
|
||||
|
||||
// { PAD_PIN13}, // 0 : gpio2 / 1 : UART0 RTSn / 3 : SPI1 SSn
|
||||
// { PAD_PIN14}, // 0 : gpio3 / 1 : UART0 CTSn / 3 : SPI1 MOSI
|
||||
// { PAD_PIN15}, // 0 : gpio4 / 1 : UART0 RXD / 3 : SPI1 MISO
|
||||
// { PAD_PIN16}, // 0 : gpio5 / 1 : UART0 TXD / 3 : SPI1 SCLK
|
||||
#define RTE_SPI1_SSN_BIT 13
|
||||
#define RTE_SPI1_SSN_FUNC PAD_MUX_ALT3
|
||||
|
||||
#define RTE_SPI1_MOSI_BIT 14
|
||||
#define RTE_SPI1_MOSI_FUNC PAD_MUX_ALT3
|
||||
|
||||
#define RTE_SPI1_MISO_BIT 15
|
||||
#define RTE_SPI1_MISO_FUNC PAD_MUX_ALT3
|
||||
|
||||
#define RTE_SPI1_SCLK_BIT 16
|
||||
#define RTE_SPI1_SCLK_FUNC PAD_MUX_ALT3
|
||||
|
||||
#define RTE_SPI1_SSN_GPIO_INSTANCE 0
|
||||
#define RTE_SPI1_SSN_GPIO_INDEX 2
|
||||
|
||||
// DMA
|
||||
// Tx
|
||||
// Channel <0=>0 <1=>1 <2=>2 <3=>3 <4=>4 <5=>5 <6=>6 <7=>7
|
||||
#define RTE_SPI1_DMA_TX_REQID DMA_REQUEST_SPI1_TX
|
||||
|
||||
// Rx
|
||||
// Channel <0=>0 <1=>1 <2=>2 <3=>3 <4=>4 <5=>5 <6=>6 <7=>7
|
||||
#define RTE_SPI1_DMA_RX_REQID DMA_REQUEST_SPI1_RX
|
||||
|
||||
|
||||
// PWM0 Controller [Driver_PWM0]
|
||||
// Configuration settings for Driver_PWM0 in component ::Drivers:PWM
|
||||
#define RTE_PWM 1
|
||||
|
||||
#define EFUSE_INIT_MODE POLLING_MODE
|
||||
#define L2CTLS_INIT_MODE POLLING_MODE
|
||||
|
||||
#define FLASH_BARE_RW_MODE 1
|
||||
|
||||
|
||||
|
||||
|
||||
#define RTE_UART0 1
|
||||
#define RTE_UART1 1
|
||||
#define RTE_UART2 1
|
||||
/* to enable external thermal */
|
||||
#define EXTERNAL_NTC_EXIST 0
|
||||
|
||||
|
||||
#if (RTE_UART1 == 1)
|
||||
#define UART1_DTR_PAD_INDEX 26 // GPIO11
|
||||
#define UART1_DTR_GPIO_INSTANCE 0
|
||||
#define UART1_DTR_GPIO_PIN 11
|
||||
|
||||
#define UART1_RI_PAD_INDEX 44 // AONIO 4 = GPIO24
|
||||
#define UART1_RI_GPIO_INSTANCE 1
|
||||
#define UART1_RI_GPIO_PIN 8
|
||||
#define UART1_RI_PWM_INSTANCE 1
|
||||
#define UART1_RI_PWM_CLK_ID FCLK_TIMER1
|
||||
#define UART1_RI_PWM_CLK_SEL FCLK_TIMER1_SEL_26M
|
||||
|
||||
#define UART1_DCD_PAD_INDEX 45 // AONIO 5 = GPIO25
|
||||
#define UART1_DCD_GPIO_INSTANCE 1
|
||||
#define UART1_DCD_GPIO_PIN 9
|
||||
#endif
|
||||
|
||||
#if (RTE_UART2 == 1)
|
||||
#define UART2_DTR_PAD_INDEX 25 // GPIO10
|
||||
#define UART2_DTR_GPIO_INSTANCE 0
|
||||
#define UART2_DTR_GPIO_PIN 10
|
||||
|
||||
#define UART2_RI_PAD_INDEX 43 // AONIO 3 = GPIO23
|
||||
#define UART2_RI_GPIO_INSTANCE 1
|
||||
#define UART2_RI_GPIO_PIN 7
|
||||
#define UART2_RI_PWM_INSTANCE 0
|
||||
#define UART2_RI_PWM_CLK_ID FCLK_TIMER0
|
||||
#define UART2_RI_PWM_CLK_SEL FCLK_TIMER0_SEL_26M
|
||||
|
||||
#define UART2_DCD_PAD_INDEX 47 // AONIO 7 = GPIO27
|
||||
#define UART2_DCD_GPIO_INSTANCE 1
|
||||
#define UART2_DCD_GPIO_PIN 11
|
||||
#endif
|
||||
|
||||
|
||||
#define NETLIGHT_PAD_INDEX 46 // AONIO 6 = GPIO26
|
||||
#define NETLIGHT_PAD_ALT_FUNC PAD_MUX_ALT5
|
||||
#define NETLIGHT_PWM_INSTANCE 3
|
||||
|
||||
//USIM1 OPTION1
|
||||
#define USIM1_URST_OP1_PAD_INDEX 19 // GPIO4
|
||||
#define USIM1_URST_OP1_GPIO_INSTANCE 0
|
||||
#define USIM1_URST_OP1_GPIO_PIN 4
|
||||
#define USIM1_UCLK_OP1_PAD_INDEX 20 // GPIO5
|
||||
#define USIM1_UCLK_OP1_GPIO_INSTANCE 0
|
||||
#define USIM1_UCLK_OP1_GPIO_PIN 5
|
||||
#define USIM1_UIO_OP1_PAD_INDEX 21 // GPIO6
|
||||
#define USIM1_UIO_OP1_GPIO_INSTANCE 0
|
||||
#define USIM1_UIO_OP1_GPIO_PIN 6
|
||||
|
||||
//USIM1 OPTION2
|
||||
#define USIM1_UIO_OP2_PAD_INDEX 27 // GPIO12
|
||||
#define USIM1_UIO_OP2_GPIO_INSTANCE 0
|
||||
#define USIM1_UIO_OP2_GPIO_PIN 12
|
||||
#define USIM1_URST_OP2_PAD_INDEX 28 // GPIO13
|
||||
#define USIM1_URST_OP2_GPIO_INSTANCE 0
|
||||
#define USIM1_URST_OP2_GPIO_PIN 13
|
||||
#define USIM1_UCLK_OP2_PAD_INDEX 29 // GPIO14
|
||||
#define USIM1_UCLK_OP2_GPIO_INSTANCE 0
|
||||
#define USIM1_UCLK_OP2_GPIO_PIN 14
|
||||
|
||||
//USIM1 clock latched by AONIO, for example, use AONIO-6 test on EVB
|
||||
#define AONIO_6_PAD_INDEX 46 // AONIO 6 = GPIO26
|
||||
#define AONIO_6_GPIO_INSTANCE 1
|
||||
#define AONIO_6_GPIO_PIN 10
|
||||
|
||||
#define RTE_CSPI0 0
|
||||
|
||||
#define RTE_CSPI0_MCLK_PAD_ADDR 39
|
||||
#define RTE_CSPI0_MCLK_FUNC PAD_MUX_ALT1
|
||||
|
||||
#define RTE_CSPI0_PCLK_PAD_ADDR 35
|
||||
#define RTE_CSPI0_PCLK_FUNC PAD_MUX_ALT1
|
||||
|
||||
#define RTE_CSPI0_CS_PAD_ADDR 36
|
||||
#define RTE_CSPI0_CS_FUNC PAD_MUX_ALT1
|
||||
|
||||
#define RTE_CSPI0_SDO0_PAD_ADDR 37
|
||||
#define RTE_CSPI0_SDO0_FUNC PAD_MUX_ALT1
|
||||
|
||||
#define RTE_CSPI0_SDO1_PAD_ADDR 38
|
||||
#define RTE_CSPI0_SDO1_FUNC PAD_MUX_ALT1
|
||||
|
||||
// DMA CSPI0 Request ID
|
||||
#define RTE_CSPI0_DMA_RX_REQID DMA_REQUEST_I2S0_RX
|
||||
|
||||
// CSPI1 Configuration
|
||||
#define RTE_CSPI1 1
|
||||
|
||||
#define RTE_CSPI1_MCLK_PAD_ADDR 18
|
||||
#define RTE_CSPI1_MCLK_FUNC PAD_MUX_ALT1
|
||||
|
||||
#define RTE_CSPI1_PCLK_PAD_ADDR 19
|
||||
#define RTE_CSPI1_PCLK_FUNC PAD_MUX_ALT1
|
||||
|
||||
#define RTE_CSPI1_CS_PAD_ADDR 20
|
||||
#define RTE_CSPI1_CS_FUNC PAD_MUX_ALT1
|
||||
|
||||
#define RTE_CSPI1_SDO0_PAD_ADDR 21
|
||||
#define RTE_CSPI1_SDO0_FUNC PAD_MUX_ALT1
|
||||
|
||||
#define RTE_CSPI1_SDO1_PAD_ADDR 22
|
||||
#define RTE_CSPI1_SDO1_FUNC PAD_MUX_ALT1
|
||||
|
||||
// DMA CSPI1 Request ID
|
||||
#define RTE_CSPI1_DMA_RX_REQID DMA_REQUEST_I2S1_RX
|
||||
|
||||
#endif /* __RTE_DEVICE_H */
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,39 @@
|
||||
#ifndef __AUDIO_EXTERN_H__
|
||||
#define __AUDIO_EXTERN_H__
|
||||
extern const unsigned char audio0[];
|
||||
extern const unsigned char audio1[];
|
||||
extern const unsigned char audio10[];
|
||||
extern const unsigned char audio100[];
|
||||
extern const unsigned char audio1000[];
|
||||
extern const unsigned char audio10000[];
|
||||
extern const unsigned char audio2[];
|
||||
extern const unsigned char audio3[];
|
||||
extern const unsigned char audio4[];
|
||||
extern const unsigned char audio5[];
|
||||
extern const unsigned char audio6[];
|
||||
extern const unsigned char audio7[];
|
||||
extern const unsigned char audio8[];
|
||||
extern const unsigned char audio9[];
|
||||
extern const unsigned char audiodot[];
|
||||
extern const unsigned char audioshoukuanchenggong[];
|
||||
extern const unsigned char audioyuan[];
|
||||
extern const unsigned char audiozhifubao[];
|
||||
extern const int audio0Size;
|
||||
extern const int audio1Size;
|
||||
extern const int audio10Size;
|
||||
extern const int audio100Size;
|
||||
extern const int audio1000Size;
|
||||
extern const int audio10000Size;
|
||||
extern const int audio2Size;
|
||||
extern const int audio3Size;
|
||||
extern const int audio4Size;
|
||||
extern const int audio5Size;
|
||||
extern const int audio6Size;
|
||||
extern const int audio7Size;
|
||||
extern const int audio8Size;
|
||||
extern const int audio9Size;
|
||||
extern const int audiodotSize;
|
||||
extern const int audioshoukuanchenggongSize;
|
||||
extern const int audioyuanSize;
|
||||
extern const int audiozhifubaoSize;
|
||||
#endif
|
||||
@@ -0,0 +1,40 @@
|
||||
#ifndef __AUDIO_TASK__
|
||||
#define __AUDIO_TASK__
|
||||
#include "queue.h"
|
||||
#include "audio_play.h"
|
||||
typedef struct
|
||||
{
|
||||
uint32_t priority;
|
||||
uint32_t playType;
|
||||
union
|
||||
{
|
||||
struct
|
||||
{
|
||||
char *data;
|
||||
uint8_t len;
|
||||
} tts;
|
||||
struct
|
||||
{
|
||||
audio_play_info_t *info;
|
||||
uint8_t count;
|
||||
} file;
|
||||
} message;
|
||||
void * userParam;
|
||||
} audioQueueData;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
MONEY_PLAY = 0,
|
||||
PAD_PLAY,
|
||||
SYS_PLAY
|
||||
} AUDIO_PLAY_PRIORITY;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
TTS_PLAY = 0,
|
||||
FILE_PLAY,
|
||||
} AUDIO_PLAY_TYPE;
|
||||
|
||||
|
||||
void audio_task_init(void);
|
||||
#endif
|
||||
@@ -0,0 +1,5 @@
|
||||
#ifndef __CHARGE_MAN_H
|
||||
#define __CHARGE_MAN_H
|
||||
uint16_t getVbat();
|
||||
void charge_init(void);
|
||||
#endif
|
||||
@@ -0,0 +1,4 @@
|
||||
#ifndef __FDB_INIT_H
|
||||
#define __FDB_INIT_H
|
||||
void fdb_init(void);
|
||||
#endif
|
||||
@@ -0,0 +1,4 @@
|
||||
#ifndef __KEY_INIT_H
|
||||
#define __KEY_INIT_H
|
||||
void key_pad_init(void);
|
||||
#endif
|
||||
@@ -0,0 +1,17 @@
|
||||
#ifndef __LED_TASK_H_
|
||||
#define __LED_TASK_H_
|
||||
|
||||
#define LED_GREEN_PAD 44
|
||||
#define LED_GREEN_PORT 1
|
||||
#define LED_GREEN_PIN 8
|
||||
|
||||
#define LED_RED_PAD 47
|
||||
#define LED_RED_PORT 1
|
||||
#define LED_RED_PIN 11
|
||||
|
||||
#define LED_BLUE_PAD 41
|
||||
#define LED_BLUE_PORT 1
|
||||
#define LED_BLUE_PIN 7
|
||||
|
||||
void led_task_init(void);
|
||||
#endif
|
||||
@@ -0,0 +1,5 @@
|
||||
#ifndef __MQTT_STATUS_H_
|
||||
#define __MQTT_STATUS_H_
|
||||
bool getNetStatus();
|
||||
bool getServerStatus();
|
||||
#endif
|
||||
@@ -0,0 +1,238 @@
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
#include "queue.h"
|
||||
#include "common_api.h"
|
||||
#include "audio_task.h"
|
||||
#include "timers.h"
|
||||
#include "portmacro.h"
|
||||
#include "audio_play.h"
|
||||
#include "ivTTS.h"
|
||||
#include "slpman.h"
|
||||
#include "gpio.h"
|
||||
#include "pad.h"
|
||||
#define WAIT_PLAY_FLAG (0x1)
|
||||
#include "common_api.h"
|
||||
#include "bsp_custom.h"
|
||||
#include "ostask.h"
|
||||
#include DEBUG_LOG_HEADER_FILE
|
||||
#include "plat_config.h"
|
||||
#include "audio_play.h"
|
||||
#include "audio_ll_drv.h"
|
||||
#include "FreeRTOS.h"
|
||||
#include "timers.h"
|
||||
#include "slpman.h"
|
||||
#include "osasys.h"
|
||||
#include "version.h"
|
||||
#include "ivTTS.h"
|
||||
#include "audio_extern.h"
|
||||
#include "led_task.h"
|
||||
extern BOOL g_green_led_status;
|
||||
extern BOOL g_red_led_status;
|
||||
extern BOOL g_blue_led_status;
|
||||
extern const unsigned char audiopoweron[];
|
||||
static osEventFlagsId_t waitAudioPlayDone = NULL;
|
||||
QueueHandle_t audioQueueHandle = NULL;
|
||||
static uint8_t audio_sleep_handler = 0xff;
|
||||
static TimerHandle_t delay_timer;
|
||||
void before_sleep(void *pdata, slpManLpState state)
|
||||
{
|
||||
slpManAONIOLatchEn(true);
|
||||
}
|
||||
/**
|
||||
\brief definition of restore callback(called after sleep)
|
||||
*/
|
||||
void after_sleep(void *pdata, slpManLpState state)
|
||||
{
|
||||
GpioPinConfig_t gpio_config;
|
||||
gpio_config.pinDirection = GPIO_DIRECTION_OUTPUT;
|
||||
gpio_config.misc.initOutput = 0;
|
||||
GPIO_pinConfig(0, 12, &gpio_config);
|
||||
gpio_config.misc.initOutput = 0;
|
||||
GPIO_pinConfig(1, 9, &gpio_config);
|
||||
|
||||
|
||||
PadConfig_t padConfig;
|
||||
PAD_getDefaultConfig(&padConfig);
|
||||
padConfig.mux = PAD_MUX_ALT0;
|
||||
PAD_setPinConfig(LED_GREEN_PAD, &padConfig);
|
||||
PAD_setPinConfig(LED_RED_PAD, &padConfig);
|
||||
PAD_setPinConfig(LED_BLUE_PAD, &padConfig);
|
||||
|
||||
gpio_config.pinDirection = GPIO_DIRECTION_OUTPUT;
|
||||
if (!getNetStatus())
|
||||
{
|
||||
gpio_config.misc.initOutput = g_green_led_status ? 0 : 1;
|
||||
GPIO_pinConfig(LED_GREEN_PORT, LED_GREEN_PIN, &gpio_config);
|
||||
gpio_config.misc.initOutput = 0;
|
||||
GPIO_pinConfig(LED_RED_PORT, LED_RED_PIN, &gpio_config);
|
||||
GPIO_pinConfig(LED_BLUE_PORT, LED_BLUE_PIN, &gpio_config);
|
||||
}
|
||||
else if ((usb_portmon_vbuspad_level() == 1))
|
||||
{
|
||||
gpio_config.misc.initOutput = 1;
|
||||
GPIO_pinConfig(LED_RED_PORT, LED_RED_PIN, &gpio_config);
|
||||
gpio_config.misc.initOutput = 0;
|
||||
GPIO_pinConfig(LED_GREEN_PORT, LED_GREEN_PIN, &gpio_config);
|
||||
GPIO_pinConfig(LED_BLUE_PORT, LED_BLUE_PIN, &gpio_config);
|
||||
}
|
||||
else if (getNetStatus() && !getServerStatus())
|
||||
{
|
||||
gpio_config.misc.initOutput = 1;
|
||||
GPIO_pinConfig(LED_BLUE_PORT, LED_BLUE_PIN, &gpio_config);
|
||||
gpio_config.misc.initOutput = 0;
|
||||
GPIO_pinConfig(LED_RED_PORT, LED_RED_PIN, &gpio_config);
|
||||
GPIO_pinConfig(LED_GREEN_PORT, LED_GREEN_PIN, &gpio_config);
|
||||
}
|
||||
else if (getServerStatus())
|
||||
{
|
||||
gpio_config.misc.initOutput = 1;
|
||||
GPIO_pinConfig(LED_BLUE_PORT, LED_BLUE_PIN, &gpio_config);
|
||||
gpio_config.misc.initOutput = 0;
|
||||
GPIO_pinConfig(LED_RED_PORT, LED_RED_PIN, &gpio_config);
|
||||
GPIO_pinConfig(LED_GREEN_PORT, LED_GREEN_PIN, &gpio_config);
|
||||
}
|
||||
}
|
||||
void audio_data_cb(uint8_t *data, uint32_t len, uint8_t bits, uint8_t channels)
|
||||
{
|
||||
//这里可以对音频数据进行软件音量缩放,或者直接清空来静音
|
||||
//软件音量缩放参考HAL_I2sSrcAdjustVolumn
|
||||
int value = 4;
|
||||
int ret = am_kv_get("volume", &value, 1);
|
||||
if(ret > 0)
|
||||
{
|
||||
DBG("AUDIO GET VOLUME SUCCESS %d", value);
|
||||
HAL_I2sSrcAdjustVolumn(data, len, value);
|
||||
}
|
||||
else
|
||||
{
|
||||
DBG("AUDIO GET VOLUME FAIL %d", value);
|
||||
HAL_I2sSrcAdjustVolumn(data, len, 4);
|
||||
}
|
||||
DBG("%x,%d,%d,%d", data, len, bits, channels);
|
||||
}
|
||||
void app_pa_on(uint32_t arg)
|
||||
{
|
||||
GPIO_pinWrite(1, 1 << 9, 1 << 9);
|
||||
}
|
||||
void audio_event_cb(uint32_t event, void *param)
|
||||
{
|
||||
DBG("%d", event);
|
||||
switch (event)
|
||||
{
|
||||
case MULTIMEDIA_CB_AUDIO_DECODE_START:
|
||||
slpManPlatVoteDisableSleep(audio_sleep_handler, SLP_SLP1_STATE);
|
||||
GPIO_pinWrite(0, 1 << 12, 1 << 12);
|
||||
audio_play_write_blank_raw(0, 6);
|
||||
break;
|
||||
case MULTIMEDIA_CB_AUDIO_OUTPUT_START:
|
||||
xTimerStart(delay_timer, 200);
|
||||
break;
|
||||
case MULTIMEDIA_CB_TTS_INIT:
|
||||
if (4 == sizeof("你好"))
|
||||
{
|
||||
audio_play_tts_set_param(0, ivTTS_PARAM_INPUT_CODEPAGE, ivTTS_CODEPAGE_GBK);
|
||||
}
|
||||
else
|
||||
{
|
||||
audio_play_tts_set_param(0, ivTTS_PARAM_INPUT_CODEPAGE, ivTTS_CODEPAGE_UTF8);
|
||||
}
|
||||
break;
|
||||
case MULTIMEDIA_CB_AUDIO_DONE:
|
||||
xTimerStop(delay_timer, 0);
|
||||
DBG("audio play done, result = %d!", audio_play_get_last_error(0));
|
||||
GPIO_pinWrite(1, 1 << 9, 0);
|
||||
GPIO_pinWrite(0, 1 << 12, 0);
|
||||
slpManPlatVoteEnableSleep(audio_sleep_handler, SLP_SLP1_STATE);
|
||||
osEventFlagsSet(waitAudioPlayDone, WAIT_PLAY_FLAG);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void audio_task(void *param)
|
||||
{
|
||||
audioQueueData audioQueueRecv = {0};
|
||||
uint32_t result = 0;
|
||||
while (1)
|
||||
{
|
||||
if (xQueueReceive(audioQueueHandle, &audioQueueRecv, portMAX_DELAY))
|
||||
{
|
||||
DBG("this is play priority %d", audioQueueRecv.priority);
|
||||
DBG("this is play playType %d", audioQueueRecv.playType);
|
||||
if (audioQueueRecv.priority == MONEY_PLAY)
|
||||
{
|
||||
|
||||
if (audioQueueRecv.playType == TTS_PLAY)
|
||||
{
|
||||
audio_play_tts_text(0, audioQueueRecv.message.tts.data, audioQueueRecv.message.tts.len);
|
||||
}
|
||||
else if (audioQueueRecv.playType == FILE_PLAY)
|
||||
{
|
||||
audio_play_multi_files(0, audioQueueRecv.message.file.info, audioQueueRecv.message.file.count);
|
||||
}
|
||||
}
|
||||
else if (audioQueueRecv.priority == PAD_PLAY)
|
||||
{
|
||||
}
|
||||
result = osEventFlagsWait(waitAudioPlayDone, WAIT_PLAY_FLAG, osFlagsWaitAll, 20000);
|
||||
DBG("this is play wait result %d", result);
|
||||
if (audioQueueRecv.playType == TTS_PLAY) {
|
||||
DBG("free tts data");
|
||||
free(audioQueueRecv.message.tts.data);
|
||||
}
|
||||
else if(audioQueueRecv.playType == FILE_PLAY)
|
||||
{
|
||||
free(audioQueueRecv.message.file.info);
|
||||
DBG("free file data");
|
||||
}
|
||||
}
|
||||
}
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
void audio_task_init(void)
|
||||
{
|
||||
GpioPinConfig_t gpio_config;
|
||||
gpio_config.pinDirection = GPIO_DIRECTION_OUTPUT;
|
||||
gpio_config.misc.initOutput = 0;
|
||||
GPIO_pinConfig(0, 12, &gpio_config);
|
||||
|
||||
PadConfig_t config;
|
||||
PAD_getDefaultConfig(&config);
|
||||
config.mux = PAD_MUX_ALT0;
|
||||
PAD_setPinConfig(45, &config);
|
||||
|
||||
GPIO_pinConfig(1, 9, &gpio_config);
|
||||
slpManRegisterUsrdefinedBackupCb(before_sleep, NULL);
|
||||
slpManRegisterUsrdefinedRestoreCb(after_sleep, NULL);
|
||||
ivCStrA sdk_id = AISOUND_SDK_USERID;
|
||||
slpManSetPmuSleepMode(true, SLP_SLP1_STATE, false);
|
||||
slpManApplyPlatVoteHandle("audio", &audio_sleep_handler);
|
||||
|
||||
slpManPlatVoteDisableSleep(audio_sleep_handler, SLP_SLP2_STATE);
|
||||
delay_timer = xTimerCreate(NULL, 200, 0, 0, app_pa_on);
|
||||
|
||||
audio_play_global_init(audio_event_cb, audio_data_cb, NULL);
|
||||
audio_play_tts_set_resource(ivtts_16k_lite, sdk_id);
|
||||
//现在使用ES7149/ES7148,用如下配置,如果不是,请根据实际情况配置,bus_id直接写0
|
||||
// Audio_CodecI2SInit(0, I2S_MODE_I2S, I2S_FRAME_SIZE_16_16);
|
||||
|
||||
//如下配置可使用TM8211
|
||||
Audio_CodecI2SInit(0, I2S_MODE_MSB, I2S_FRAME_SIZE_16_16);
|
||||
if (waitAudioPlayDone == NULL)
|
||||
{
|
||||
waitAudioPlayDone = osEventFlagsNew(NULL);
|
||||
}
|
||||
audioQueueHandle = xQueueCreate(100, sizeof(audioQueueData));
|
||||
audioQueueData powerOn = {0};
|
||||
powerOn.playType = TTS_PLAY;
|
||||
powerOn.priority = MONEY_PLAY;
|
||||
char str[] = "正在开机";
|
||||
powerOn.message.tts.data = malloc(sizeof(str));
|
||||
memcpy(powerOn.message.tts.data, str, sizeof(str));
|
||||
powerOn.message.tts.len = sizeof(str);
|
||||
if (pdTRUE != xQueueSend(audioQueueHandle, &powerOn, 0))
|
||||
{
|
||||
DBG("start send audio fail");
|
||||
}
|
||||
xTaskCreate(audio_task, " ", 2048, NULL, 20, NULL);
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
#include "queue.h"
|
||||
#include "cmsis_os2.h"
|
||||
#include "adc.h"
|
||||
#include "common_api.h"
|
||||
#include "plat_config.h"
|
||||
#include "charge_management.h"
|
||||
#define VBAT_FLAG (0x1)
|
||||
static osEventFlagsId_t getVbatFlag = NULL;
|
||||
volatile static uint32_t vbatChannelResult = 0;
|
||||
volatile static uint16_t vbat = 0;
|
||||
|
||||
uint16_t getVbat()
|
||||
{
|
||||
return vbat;
|
||||
}
|
||||
static void ADC_VbatChannelCallback(uint32_t result)
|
||||
{
|
||||
vbatChannelResult = result;
|
||||
osEventFlagsSet(getVbatFlag, VBAT_FLAG);
|
||||
}
|
||||
|
||||
static void charge_task(void *param)
|
||||
{
|
||||
AdcConfig_t adcConfig;
|
||||
ADC_getDefaultConfig(&adcConfig);
|
||||
adcConfig.channelConfig.vbatResDiv = ADC_VBAT_RESDIV_RATIO_3OVER16;
|
||||
uint32_t result = 0;
|
||||
while (1)
|
||||
{
|
||||
ADC_channelInit(ADC_CHANNEL_VBAT, ADC_USER_PLAT, &adcConfig, ADC_VbatChannelCallback);
|
||||
ADC_startConversion(ADC_CHANNEL_VBAT, ADC_USER_PLAT);
|
||||
result = osEventFlagsWait(getVbatFlag, VBAT_FLAG, osFlagsWaitAll, 3000);
|
||||
if (result == VBAT_FLAG)
|
||||
{
|
||||
vbat = (HAL_ADC_CalibrateRawCode(vbatChannelResult) * 16 / 3 + 500) / 1000;
|
||||
DBG("get vbat result %d", vbat);
|
||||
}
|
||||
else
|
||||
{
|
||||
DBG("get vbat timeout");
|
||||
}
|
||||
ADC_channelDeInit(ADC_CHANNEL_VBAT, ADC_USER_PLAT);
|
||||
osDelay(60000); // 60S获取一次当前电量
|
||||
}
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
void charge_init()
|
||||
{
|
||||
if (getVbatFlag == NULL)
|
||||
{
|
||||
getVbatFlag = osEventFlagsNew(NULL);
|
||||
}
|
||||
xTaskCreate(charge_task, "", 256, NULL, 20, NULL);
|
||||
}
|
||||
@@ -0,0 +1,652 @@
|
||||
/*
|
||||
* Copyright (c) 2022 OpenLuat & AirM2M
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to
|
||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "bsp.h"
|
||||
#include "bsp_custom.h"
|
||||
#include "common_api.h"
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
#include "queue.h"
|
||||
#include "ps_event_callback.h"
|
||||
#include "ps_lib_api.h"
|
||||
#include "cmisim.h"
|
||||
#include "cmips.h"
|
||||
#include "slpman.h"
|
||||
#include "cJSON.h"
|
||||
#include "MQTTClient.h"
|
||||
#include "audio_task.h"
|
||||
#include "audioFile.h"
|
||||
#include "audio_play.h"
|
||||
#include "math.h"
|
||||
#include "charge_management.h"
|
||||
#include "key_pad.h"
|
||||
#include "am_kv.h"
|
||||
#include "led_task.h"
|
||||
#include "plat_config.h"
|
||||
#include "fdb_init.h"
|
||||
#include "cmimm.h"
|
||||
extern QueueHandle_t audioQueueHandle;
|
||||
|
||||
#define MQTT_HOST "lbsmqtt.airm2m.com" // MQTT服务器的地址和端口号
|
||||
#define MQTT_PORT 1884
|
||||
#define CLIENT_ID "123456789"
|
||||
#define USERNAME "username"
|
||||
#define PASSWORD "password"
|
||||
|
||||
const static char mqtt_sub_topic[] = "/sub/topic/money"; //订阅的主题
|
||||
const static char mqtt_pub_topic[] = "/pub/topic/message"; //发布的主题
|
||||
static char mqtt_send_payload[] = "hello mqtt_test!!!";
|
||||
|
||||
#define QMSG_ID_BASE (0x160)
|
||||
#define QMSG_ID_NW_IPV4_READY (QMSG_ID_BASE)
|
||||
#define QMSG_ID_NW_IPV6_READY (QMSG_ID_BASE + 1)
|
||||
#define QMSG_ID_NW_IPV4_6_READY (QMSG_ID_BASE + 2)
|
||||
#define QMSG_ID_NW_DISCONNECT (QMSG_ID_BASE + 3)
|
||||
#define QMSG_ID_SOCK_SENDPKG (QMSG_ID_BASE + 4)
|
||||
#define QMSG_ID_SOCK_RECVPKG (QMSG_ID_BASE + 5)
|
||||
|
||||
|
||||
#define APP_EVENT_QUEUE_SIZE (10)
|
||||
static QueueHandle_t psEventQueueHandle;
|
||||
static bool netStatus = false;
|
||||
static bool serverStatus = false;
|
||||
|
||||
bool getNetStatus()
|
||||
{
|
||||
return netStatus;
|
||||
}
|
||||
bool getServerStatus()
|
||||
{
|
||||
return serverStatus;
|
||||
}
|
||||
static void sendQueueMsg(UINT32 msgId, UINT32 xTickstoWait){
|
||||
eventCallbackMessage_t *queueMsg = NULL;
|
||||
queueMsg = malloc(sizeof(eventCallbackMessage_t));
|
||||
queueMsg->messageId = msgId;
|
||||
if (psEventQueueHandle){
|
||||
if (pdTRUE != xQueueSend(psEventQueueHandle, &queueMsg, xTickstoWait)){
|
||||
DBG("xQueueSend error");
|
||||
}
|
||||
}
|
||||
}
|
||||
int fomatMoney(int num, audioQueueData *data, int *index, BOOL flag)
|
||||
{
|
||||
uint32_t audioArray[10][2] =
|
||||
{
|
||||
{audio0, sizeof(audio0)},
|
||||
{audio1, sizeof(audio1)},
|
||||
{audio2, sizeof(audio2)},
|
||||
{audio3, sizeof(audio3)},
|
||||
{audio4, sizeof(audio4)},
|
||||
{audio5, sizeof(audio5)},
|
||||
{audio6, sizeof(audio6)},
|
||||
{audio7, sizeof(audio7)},
|
||||
{audio8, sizeof(audio8)},
|
||||
{audio9, sizeof(audio9)}
|
||||
};
|
||||
int thousand = (num - num % 1000) / 1000;
|
||||
int hundred = ((num % 1000) - ((num % 1000) % 100)) / 100;
|
||||
int ten = ((num % 100) - ((num % 100) % 10)) / 10;
|
||||
int unit = num % 10;
|
||||
if (thousand == 0)
|
||||
{
|
||||
thousand = -1;
|
||||
if (hundred == 0)
|
||||
{
|
||||
hundred = -1;
|
||||
if (ten == 0)
|
||||
{
|
||||
ten = -1;
|
||||
if (unit == 0)
|
||||
{
|
||||
unit = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (unit == 0)
|
||||
{
|
||||
unit = -1;
|
||||
if (ten == 0)
|
||||
{
|
||||
ten = -1;
|
||||
if (hundred == 0)
|
||||
{
|
||||
hundred = -1;
|
||||
if (thousand == 0)
|
||||
{
|
||||
thousand = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (ten == 0 && hundred == 0)
|
||||
{
|
||||
ten = -1;
|
||||
}
|
||||
if (thousand != -1)
|
||||
{
|
||||
if (flag)
|
||||
{
|
||||
data->message.file.info[*index].path = NULL;
|
||||
data->message.file.info[*index].address = audioArray[thousand][0];
|
||||
data->message.file.info[*index].rom_data_len = audioArray[thousand][1];
|
||||
}
|
||||
*index += 1;
|
||||
if (flag)
|
||||
{
|
||||
data->message.file.info[*index].path = NULL;
|
||||
data->message.file.info[*index].address = audio1000;
|
||||
data->message.file.info[*index].rom_data_len = sizeof(audio1000);
|
||||
}
|
||||
*index += 1;
|
||||
}
|
||||
if (hundred != -1)
|
||||
{
|
||||
if(flag)
|
||||
{
|
||||
data->message.file.info[*index].path = NULL;
|
||||
data->message.file.info[*index].address = audioArray[hundred][0];
|
||||
data->message.file.info[*index].rom_data_len = audioArray[hundred][1];
|
||||
}
|
||||
*index += 1;
|
||||
if(flag)
|
||||
{
|
||||
data->message.file.info[*index].path = NULL;
|
||||
data->message.file.info[*index].address = audio100;
|
||||
data->message.file.info[*index].rom_data_len = sizeof(audio100);
|
||||
}
|
||||
*index += 1;
|
||||
}
|
||||
if (ten != -1)
|
||||
{
|
||||
if (!(ten == 1 && hundred == -1 && thousand == -1))
|
||||
{
|
||||
if(flag)
|
||||
{
|
||||
data->message.file.info[*index].path = NULL;
|
||||
data->message.file.info[*index].address = audioArray[ten][0];
|
||||
data->message.file.info[*index].rom_data_len = audioArray[ten][1];
|
||||
}
|
||||
*index += 1;
|
||||
}
|
||||
DBG("333 %d\r\n", *index);
|
||||
if (ten != 0)
|
||||
{
|
||||
if(flag)
|
||||
{
|
||||
data->message.file.info[*index].path = NULL;
|
||||
data->message.file.info[*index].address = audio10;
|
||||
data->message.file.info[*index].rom_data_len = sizeof(audio10);
|
||||
}
|
||||
*index += 1;
|
||||
}
|
||||
}
|
||||
if (unit != -1)
|
||||
{
|
||||
if(flag)
|
||||
{
|
||||
data->message.file.info[*index].path = NULL;
|
||||
data->message.file.info[*index].address = audioArray[unit][0];
|
||||
data->message.file.info[*index].rom_data_len = audioArray[unit][1];
|
||||
}
|
||||
*index += 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
static int strToFile(char *money, audioQueueData *data, int *index, bool flag)
|
||||
{
|
||||
if (flag)
|
||||
{
|
||||
data->message.file.info[*index].address = audiozhifubao;
|
||||
data->message.file.info[*index].rom_data_len = sizeof(audiozhifubao);
|
||||
}
|
||||
*index += 1;
|
||||
uint32_t audioArray[10][2] =
|
||||
{
|
||||
{audio0, sizeof(audio0)},
|
||||
{audio1, sizeof(audio1)},
|
||||
{audio2, sizeof(audio2)},
|
||||
{audio3, sizeof(audio3)},
|
||||
{audio4, sizeof(audio4)},
|
||||
{audio5, sizeof(audio5)},
|
||||
{audio6, sizeof(audio6)},
|
||||
{audio7, sizeof(audio7)},
|
||||
{audio8, sizeof(audio8)},
|
||||
{audio9, sizeof(audio9)}
|
||||
};
|
||||
int count = 0;
|
||||
int integer = 0;
|
||||
char *str = NULL;
|
||||
char intStr[8] = {0};
|
||||
char decStr[3] = {0};
|
||||
str = strstr(money, ".");
|
||||
if (str != NULL)
|
||||
{
|
||||
memcpy(intStr, money, str - money);
|
||||
str = str + 1;
|
||||
memcpy(decStr, str, 2);
|
||||
integer = atoi(intStr);
|
||||
}
|
||||
else
|
||||
{
|
||||
integer = atoi(money);
|
||||
}
|
||||
if (integer >= 10000)
|
||||
{
|
||||
int filecount = fomatMoney(integer / 10000, data, index, flag);
|
||||
//TODO 待处理两万
|
||||
if (flag)
|
||||
{
|
||||
data->message.file.info[*index].path = NULL;
|
||||
data->message.file.info[*index].address = audio10000;
|
||||
data->message.file.info[*index].rom_data_len = sizeof(audio10000);
|
||||
}
|
||||
*index += 1;
|
||||
if (((integer % 10000) < 1000) && ((integer % 10000) != 0))
|
||||
{
|
||||
if (flag)
|
||||
{
|
||||
data->message.file.info[*index].path = NULL;
|
||||
data->message.file.info[*index].address = audioArray[0][0];
|
||||
data->message.file.info[*index].rom_data_len = audioArray[0][1];
|
||||
}
|
||||
*index += 1;
|
||||
}
|
||||
}
|
||||
if ((integer % 10000) > 0)
|
||||
{
|
||||
int filecount = fomatMoney(integer % 10000, data, index, flag);
|
||||
//TODO 待处理两千
|
||||
// if()
|
||||
// if (flag)
|
||||
// {
|
||||
// data->message.file.info[*index].path = NULL;
|
||||
// data->message.file.info[*index].address = audioK;
|
||||
// data->message.file.info[*index].rom_data_len = sizeof(audioK);
|
||||
// }
|
||||
// *index += 1;
|
||||
// count += filecount;
|
||||
}
|
||||
if (*index == 1)
|
||||
{
|
||||
if (flag)
|
||||
{
|
||||
data->message.file.info[*index].path = NULL;
|
||||
data->message.file.info[*index].address = audioArray[0][0];
|
||||
data->message.file.info[*index].rom_data_len = audioArray[0][1];
|
||||
}
|
||||
*index += 1;
|
||||
}
|
||||
int decial = atoi(decStr);
|
||||
if (decial > 0)
|
||||
{
|
||||
if (flag)
|
||||
{
|
||||
data->message.file.info[*index].path = NULL;
|
||||
data->message.file.info[*index].address = audiodot;
|
||||
data->message.file.info[*index].rom_data_len = sizeof(audiodot);
|
||||
}
|
||||
*index += 1;
|
||||
if (decial > 10)
|
||||
{
|
||||
int ten = decial / 10;
|
||||
int unit = decial % 10;
|
||||
if (ten != 0 && unit != 0)
|
||||
{
|
||||
if (flag)
|
||||
{
|
||||
data->message.file.info[*index].path = NULL;
|
||||
data->message.file.info[*index].address = audioArray[ten][0];
|
||||
data->message.file.info[*index].rom_data_len = audioArray[0][1];
|
||||
}
|
||||
*index += 1;
|
||||
if(flag)
|
||||
{
|
||||
data->message.file.info[*index].path = NULL;
|
||||
data->message.file.info[*index].address = audioArray[unit][0];
|
||||
data->message.file.info[*index].rom_data_len = audioArray[0][1];
|
||||
}
|
||||
*index += 1;
|
||||
}
|
||||
else if(ten == 0 && unit!=0)
|
||||
{
|
||||
if (flag)
|
||||
{
|
||||
data->message.file.info[*index].path = NULL;
|
||||
data->message.file.info[*index].address = audioArray[0][0];
|
||||
data->message.file.info[*index].rom_data_len = audioArray[0][1];
|
||||
}
|
||||
*index += 1;
|
||||
if(flag)
|
||||
{
|
||||
data->message.file.info[*index].path = NULL;
|
||||
data->message.file.info[*index].address = audioArray[unit][0];
|
||||
data->message.file.info[*index].rom_data_len = audioArray[0][1];
|
||||
}
|
||||
*index += 1;
|
||||
}
|
||||
else if(ten !=0 && unit == 0)
|
||||
{
|
||||
if (flag)
|
||||
{
|
||||
data->message.file.info[*index].path = NULL;
|
||||
data->message.file.info[*index].address = audioArray[0][0];
|
||||
data->message.file.info[*index].rom_data_len = audioArray[0][1];
|
||||
}
|
||||
*index += 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (flag)
|
||||
{
|
||||
data->message.file.info[*index].path = NULL;
|
||||
data->message.file.info[*index].address = audioArray[decial][0];
|
||||
data->message.file.info[*index].rom_data_len = audioArray[decial][1];
|
||||
}
|
||||
*index += 1;
|
||||
}
|
||||
}
|
||||
if (flag)
|
||||
{
|
||||
data->message.file.info[*index].path = NULL;
|
||||
data->message.file.info[*index].address = audioyuan;
|
||||
data->message.file.info[*index].rom_data_len = sizeof(audioyuan);
|
||||
}
|
||||
*index += 1;
|
||||
return count;
|
||||
}
|
||||
|
||||
static INT32 mqttPSUrcCallback(PsEventID eventID, void *param, UINT32 paramLen){
|
||||
CmiSimImsiStr *imsi = NULL;
|
||||
CmiPsCeregInd *creg = NULL;
|
||||
UINT8 rssi = 0;
|
||||
NmAtiNetInfoInd *netif = NULL;
|
||||
|
||||
switch(eventID){
|
||||
case PS_URC_ID_SIM_READY:{
|
||||
imsi = (CmiSimImsiStr *)param;
|
||||
DBG("SIM ready(imsi=%s len=%d)", imsi->contents, imsi->length);
|
||||
break;
|
||||
}
|
||||
case PS_URC_ID_MM_SIGQ:{
|
||||
CmiMmCesqInd *pMmCesqInd = (CmiMmCesqInd *)param;
|
||||
rssi = mmGetCsqRssiFromCesq(pMmCesqInd->rsrp, pMmCesqInd->rsrq, pMmCesqInd->rssiCompensation);
|
||||
DBG("RSSI signal=%d", rssi);
|
||||
break;
|
||||
}
|
||||
case PS_URC_ID_PS_BEARER_ACTED:{
|
||||
DBG("Default bearer activated");
|
||||
netStatus = true;
|
||||
break;
|
||||
}
|
||||
case PS_URC_ID_PS_BEARER_DEACTED:{
|
||||
DBG("Default bearer Deactivated");
|
||||
sendQueueMsg(QMSG_ID_NW_DISCONNECT, 0);
|
||||
break;
|
||||
}
|
||||
case PS_URC_ID_PS_CEREG_CHANGED:{
|
||||
creg = (CmiPsCeregInd *)param;
|
||||
DBG("CREG message act:%d celId:%d locPresent:%d state:%d", creg->act, creg->celId, creg->locPresent, creg->state);
|
||||
break;
|
||||
}
|
||||
case PS_URC_ID_PS_NETINFO:{
|
||||
netif = (NmAtiNetInfoInd *)param;
|
||||
if (netif->netifInfo.netStatus == NM_NETIF_ACTIVATED){
|
||||
serverStatus = true;
|
||||
netStatus = true;
|
||||
DBG("netif acivated");
|
||||
sendQueueMsg(QMSG_ID_NW_IPV4_READY, 0);
|
||||
}else if (netif->netifInfo.netStatus == NM_NETIF_OOS){
|
||||
DBG("PSIF network OOS");
|
||||
}else if (netif->netifInfo.netStatus == NM_NO_NETIF_OR_DEACTIVATED ||
|
||||
netif->netifInfo.netStatus == NM_NO_NETIF_NOT_DIAL){
|
||||
serverStatus = false;
|
||||
netStatus = false;
|
||||
DBG("PSIF network deactive");
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
void messageArrived(MessageData* data)
|
||||
{
|
||||
if (memcmp(mqtt_sub_topic, data->topicName->lenstring.data, strlen(mqtt_sub_topic)) == 0)
|
||||
{
|
||||
cJSON *boss = NULL;
|
||||
DBG("mqtt Message arrived on topic %.*s: %.*s\n", data->topicName->lenstring.len, data->topicName->lenstring.data, data->message->payloadlen, data->message->payload);
|
||||
boss = cJSON_Parse((const char *)data->message->payload);
|
||||
if (boss == NULL){
|
||||
DBG("cjson parse fail");
|
||||
}
|
||||
else
|
||||
{
|
||||
DBG("cjson parse success");
|
||||
cJSON *money = cJSON_GetObjectItem(boss, "money");
|
||||
if(money == NULL)
|
||||
{
|
||||
DBG("Missing amount field %d", money);
|
||||
return 0;
|
||||
}
|
||||
if (cJSON_IsString(money))
|
||||
{
|
||||
audioQueueData moneyPlay = {0};
|
||||
moneyPlay.priority = MONEY_PLAY;
|
||||
moneyPlay.playType = FILE_PLAY;
|
||||
char* str = strstr(money->valuestring, ".");
|
||||
//判断金额长度是否大于8个,也就是千万级别的金额,如果是,则播报收款成功,如果不是,则播报对应金额,这里并未对金额字段做合法性判断
|
||||
if (str != NULL)
|
||||
{
|
||||
if((str - money->valuestring) > 8)
|
||||
{
|
||||
moneyPlay.message.file.info = (audio_play_info_t *)calloc(1, sizeof(audio_play_info_t));
|
||||
moneyPlay.message.file.info->address = audioshoukuanchenggong;
|
||||
moneyPlay.message.file.info->rom_data_len = audioshoukuanchenggongSize;
|
||||
moneyPlay.message.file.count = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
//调用strToFile来将金额格式化为对应的文件播报数据,需要调用两次,第一次获取需要malloc的空间,第二次将文件数据放进空间里
|
||||
int index = 0;
|
||||
strToFile(money->valuestring, &moneyPlay, &index, false);
|
||||
moneyPlay.message.file.info = (audio_play_info_t *)calloc(index, sizeof(audio_play_info_t));
|
||||
index = 0;
|
||||
strToFile(money->valuestring, &moneyPlay, &index, true);
|
||||
moneyPlay.message.file.count = index;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(strlen(money->valuestring) > 8)
|
||||
{
|
||||
moneyPlay.message.file.info = (audio_play_info_t *)calloc(1, sizeof(audio_play_info_t));
|
||||
moneyPlay.message.file.info->address = audioshoukuanchenggong;
|
||||
moneyPlay.message.file.info->rom_data_len = audioshoukuanchenggongSize;
|
||||
moneyPlay.message.file.count = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
str++;
|
||||
if(strlen(str) > 2)
|
||||
{
|
||||
moneyPlay.message.file.info = (audio_play_info_t *)calloc(1, sizeof(audio_play_info_t));
|
||||
moneyPlay.message.file.info->address = audioshoukuanchenggong;
|
||||
moneyPlay.message.file.info->rom_data_len = audioshoukuanchenggongSize;
|
||||
moneyPlay.message.file.count = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
//调用strToFile来将金额格式化为对应的文件播报数据,需要调用两次,第一次获取需要malloc的空间,第二次将文件数据放进空间里
|
||||
int index = 0;
|
||||
strToFile(money->valuestring, &moneyPlay, &index, false);
|
||||
moneyPlay.message.file.info = (audio_play_info_t *)calloc(index, sizeof(audio_play_info_t));
|
||||
index = 0;
|
||||
strToFile(money->valuestring, &moneyPlay, &index, true);
|
||||
moneyPlay.message.file.count = index;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (pdTRUE != xQueueSend(audioQueueHandle, &moneyPlay, 0)){
|
||||
DBG("mqttsub xQueueSend error");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DBG("money data is invalid %d", cJSON_IsString(money));
|
||||
}
|
||||
}
|
||||
cJSON_Delete(boss);
|
||||
}
|
||||
}
|
||||
|
||||
static void mqtt_demo(void){
|
||||
int rc = 0;
|
||||
MQTTClient mqttClient = {0};
|
||||
Network mqttNetwork = {0};
|
||||
|
||||
MQTTMessage message = {0};
|
||||
MQTTPacket_connectData connectData = MQTTPacket_connectData_initializer;
|
||||
connectData.MQTTVersion = 4;
|
||||
int ret = 0;
|
||||
char str[32] = {0};
|
||||
char clientId[17] = {0};
|
||||
char username[17] = {0};
|
||||
char password[17] = {0};
|
||||
ret = am_kv_get("clientId", str, 17); //从数据库中读取clientId,如果没读到,则用默认的
|
||||
if(ret > 0 )
|
||||
{
|
||||
memcpy(clientId, str, 17);
|
||||
connectData.clientID.cstring = clientId;
|
||||
}
|
||||
else
|
||||
{
|
||||
connectData.clientID.cstring = CLIENT_ID;
|
||||
}
|
||||
memset(str, 0, 32);
|
||||
ret = am_kv_get("username", str, 17); //从数据库中读取username,如果没读到,则用默认的
|
||||
if(ret > 0 )
|
||||
{
|
||||
memcpy(username, str, 17);
|
||||
connectData.username.cstring = username;
|
||||
}
|
||||
else
|
||||
{
|
||||
connectData.username.cstring = USERNAME;
|
||||
}
|
||||
memset(str, 0, 32);
|
||||
ret = am_kv_get("password", str, 17); //从数据库中读取password,如果没读到,则用默认的
|
||||
if(ret > 0 )
|
||||
{
|
||||
memcpy(password, str, 17);
|
||||
connectData.password.cstring = password;
|
||||
}
|
||||
else
|
||||
{
|
||||
connectData.password.cstring = PASSWORD;
|
||||
}
|
||||
memset(str, 0, 32);
|
||||
DBG("test clientid %s", clientId);
|
||||
DBG("test username %s", username);
|
||||
DBG("test password %s", password);
|
||||
|
||||
connectData.keepAliveInterval = 120;
|
||||
|
||||
mqtt_connect(&mqttClient, &mqttNetwork, MQTT_HOST, MQTT_PORT, &connectData);
|
||||
|
||||
if ((rc = MQTTSubscribe(&mqttClient, mqtt_sub_topic, 0, messageArrived)) != 0)
|
||||
{
|
||||
DBG("mqtt Return code from MQTT subscribe is %d\n", rc);
|
||||
serverStatus = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
serverStatus = true;
|
||||
audioQueueData welcome = {0};
|
||||
welcome.playType = TTS_PLAY;
|
||||
welcome.priority = MONEY_PLAY;
|
||||
char str[] = "服务器连接成功";
|
||||
welcome.message.tts.data = malloc(sizeof(str));
|
||||
memcpy(welcome.message.tts.data, str, sizeof(str));
|
||||
welcome.message.tts.len = sizeof(str);
|
||||
if (pdTRUE != xQueueSend(audioQueueHandle, &welcome, 0)){
|
||||
DBG("mqttsub xQueueSend error");
|
||||
}
|
||||
}
|
||||
|
||||
while(1){
|
||||
int len = strlen(mqtt_send_payload);
|
||||
message.qos = 1;
|
||||
message.retained = 0;
|
||||
message.payload = mqtt_send_payload;
|
||||
message.payloadlen = len;
|
||||
DBG("mqtt_demo send data");
|
||||
MQTTPublish(&mqttClient, mqtt_pub_topic, &message);
|
||||
#if !defined(MQTT_TASK)
|
||||
if ((rc = MQTTYield(&mqttClient, 1000)) != 0)
|
||||
DBG("mqtt_demo Return code from yield is %d\n", rc);
|
||||
#endif
|
||||
osDelay(60000);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void mqttclient_task(void *param){
|
||||
eventCallbackMessage_t *queueItem = NULL;
|
||||
psEventQueueHandle = xQueueCreate(APP_EVENT_QUEUE_SIZE, sizeof(eventCallbackMessage_t*));
|
||||
if (psEventQueueHandle == NULL){
|
||||
DBG("psEventQueue create error!");
|
||||
return;
|
||||
}
|
||||
registerPSEventCallback(PS_GROUP_ALL_MASK, mqttPSUrcCallback);
|
||||
while(1){
|
||||
if (xQueueReceive(psEventQueueHandle, &queueItem, portMAX_DELAY)){
|
||||
switch(queueItem->messageId){
|
||||
case QMSG_ID_NW_IPV4_READY:
|
||||
case QMSG_ID_NW_IPV6_READY:
|
||||
case QMSG_ID_NW_IPV4_6_READY:
|
||||
mqtt_demo();
|
||||
break;
|
||||
case QMSG_ID_NW_DISCONNECT:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
free(queueItem);
|
||||
}
|
||||
}
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
static void mqttclient_task_init(void){
|
||||
xTaskCreate(mqttclient_task, "", 4096, NULL, 20, NULL);
|
||||
}
|
||||
extern void usb_data_init(void);
|
||||
INIT_HW_EXPORT(usb_data_init, "1");
|
||||
INIT_DRV_EXPORT(fdb_init, "2");
|
||||
INIT_TASK_EXPORT(mqttclient_task_init, "2");
|
||||
INIT_TASK_EXPORT(audio_task_init, "2");
|
||||
INIT_TASK_EXPORT(key_pad_init, "2");
|
||||
INIT_TASK_EXPORT(charge_init, "2");
|
||||
INIT_TASK_EXPORT(led_task_init, "2");
|
||||
@@ -0,0 +1,32 @@
|
||||
#include "common_api.h"
|
||||
void fdb_init(void)
|
||||
{
|
||||
am_kv_init();
|
||||
char value[2];
|
||||
int ret = am_kv_get("flag", &value, 2);
|
||||
//读取kv数据库用户是否初始化过,如果没有,则写入一个flag和需要初始化的值,表示用户已初始化;如果用户初始化过,则不做任何操作
|
||||
DBG("get value result %d", ret);
|
||||
if (ret > 0)
|
||||
{
|
||||
DBG("get value %s", value);
|
||||
if(memcmp("1", value, strlen("1")))
|
||||
{
|
||||
DBG("need init");
|
||||
ret = am_kv_set("flag", "1", 2);
|
||||
DBG("init result1 %d", ret);
|
||||
int volume = 4;
|
||||
ret = am_kv_set("volume", &volume, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
DBG("no need init");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = am_kv_set("flag", "1", 2);
|
||||
int volume = 4;
|
||||
ret = am_kv_set("volume", &volume, 1);
|
||||
DBG("init result2 %d", ret);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,313 @@
|
||||
#include "gpio.h"
|
||||
#include "pad.h"
|
||||
#include "slpman.h"
|
||||
#include "apmu_external.h"
|
||||
#include "common_api.h"
|
||||
#include "FreeRTOS.h"
|
||||
#include "timers.h"
|
||||
#include "pwrkey.h"
|
||||
#include "queue.h"
|
||||
#include "charge_management.h"
|
||||
#include "audio_task.h"
|
||||
#include "audio_extern.h"
|
||||
#define KEY1_MESSAGE 0x1
|
||||
#define KEY2_MESSAGE 0x2
|
||||
#define PWR_MESSAGE 0x3
|
||||
static QueueHandle_t padKeyEventQueueHandle;
|
||||
typedef struct
|
||||
{
|
||||
uint32_t messageId;
|
||||
} padkeyQueueMsg_t;
|
||||
TimerHandle_t timerHandlePowerOff = NULL;
|
||||
TimerHandle_t timerHandlePower = NULL;
|
||||
extern QueueHandle_t audioQueueHandle;
|
||||
TimerCallbackFunction_t timerCb(TimerHandle_t xTimer)
|
||||
{
|
||||
if (timerHandlePower == xTimer)
|
||||
{
|
||||
xTimerStart(timerHandlePowerOff, 3000);
|
||||
audioQueueData audioQueueSend = {0};
|
||||
audioQueueSend.playType = TTS_PLAY;
|
||||
audioQueueSend.priority = MONEY_PLAY;
|
||||
char str[] = "正在关机";
|
||||
audioQueueSend.message.tts.data = malloc(sizeof(str));
|
||||
memcpy(audioQueueSend.message.tts.data, str, sizeof(str));
|
||||
audioQueueSend.message.tts.len = sizeof(str);
|
||||
if (pdTRUE != xQueueSend(audioQueueHandle, &audioQueueSend, 0))
|
||||
{
|
||||
DBG("power off send audio fail");
|
||||
}
|
||||
DBG("power long press");
|
||||
}
|
||||
else if (timerHandlePowerOff == xTimer)
|
||||
{
|
||||
DBG("poweroff");
|
||||
uniLogFlushOut();
|
||||
pwrKeyStartPowerOff();
|
||||
}
|
||||
}
|
||||
|
||||
void pwrkeyStatusCb(pwrKeyPressStatus status)
|
||||
{
|
||||
BaseType_t xHigherPriorityTaskWoken;
|
||||
xHigherPriorityTaskWoken = pdFALSE;
|
||||
uint32_t msgId = PWR_MESSAGE;
|
||||
switch (status)
|
||||
{
|
||||
case PWRKEY_RELEASE:
|
||||
if (pdTRUE != xQueueSendFromISR(padKeyEventQueueHandle, &msgId, &xHigherPriorityTaskWoken))
|
||||
{
|
||||
}
|
||||
portYIELD_FROM_ISR(pdTRUE);
|
||||
break;
|
||||
case PWRKEY_PRESS:
|
||||
if (pdTRUE != xTimerStartFromISR(timerHandlePower, &xHigherPriorityTaskWoken))
|
||||
{
|
||||
}
|
||||
portYIELD_FROM_ISR(pdTRUE);
|
||||
break;
|
||||
case PWRKEY_LONGPRESS:
|
||||
break;
|
||||
case PWRKEY_REPEAT:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
#define BUTTON_GPIO_INSTANCE 1
|
||||
#define BUTTON_GPIO_PIN 10
|
||||
static void GPIO_ISR()
|
||||
{
|
||||
uint32_t msgId = KEY1_MESSAGE;
|
||||
BaseType_t xHigherPriorityTaskWoken;
|
||||
xHigherPriorityTaskWoken = pdFALSE;
|
||||
// Save current irq mask and diable whole port interrupts to get rid of interrupt overflow
|
||||
uint16_t portIrqMask = GPIO_saveAndSetIrqMask(BUTTON_GPIO_INSTANCE);
|
||||
|
||||
if (GPIO_getInterruptFlags(BUTTON_GPIO_INSTANCE) & (1 << BUTTON_GPIO_PIN))
|
||||
{
|
||||
if (pdTRUE != xQueueSendFromISR(padKeyEventQueueHandle, &msgId, &xHigherPriorityTaskWoken))
|
||||
{
|
||||
}
|
||||
GPIO_clearInterruptFlags(BUTTON_GPIO_INSTANCE, 1 << BUTTON_GPIO_PIN);
|
||||
}
|
||||
|
||||
GPIO_restoreIrqMask(BUTTON_GPIO_INSTANCE, portIrqMask);
|
||||
portYIELD_FROM_ISR(pdTRUE);
|
||||
}
|
||||
|
||||
static void pad3IsrCb()
|
||||
{
|
||||
BaseType_t xHigherPriorityTaskWoken;
|
||||
xHigherPriorityTaskWoken = pdFALSE;
|
||||
uint8_t status = slpManGetWakeupPinValue();
|
||||
uint32_t msgId = KEY2_MESSAGE;
|
||||
if ((status & 0x8) == 0) //按下
|
||||
{
|
||||
if (pdTRUE != xQueueSendFromISR(padKeyEventQueueHandle, &msgId, &xHigherPriorityTaskWoken))
|
||||
{
|
||||
}
|
||||
}
|
||||
portYIELD_FROM_ISR(pdTRUE);
|
||||
}
|
||||
|
||||
void padkeyIsrCb(int num)
|
||||
{
|
||||
switch (num)
|
||||
{
|
||||
case 3:
|
||||
pad3IsrCb();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void padKeyTask(void *arg)
|
||||
{
|
||||
uint32_t msgId = 0;
|
||||
int volume = 4;
|
||||
int ret = 0;
|
||||
while (1)
|
||||
{
|
||||
if (xQueueReceive(padKeyEventQueueHandle, &msgId, portMAX_DELAY))
|
||||
{
|
||||
switch (msgId)
|
||||
{
|
||||
case KEY1_MESSAGE:
|
||||
{
|
||||
audioQueueData volPlus = {0};
|
||||
volPlus.playType = TTS_PLAY;
|
||||
volPlus.priority = MONEY_PLAY;
|
||||
volume = 4;
|
||||
ret = am_kv_get("volume", &volume, 1);
|
||||
if (ret > 0)
|
||||
{
|
||||
if (volume < 7)
|
||||
{
|
||||
volume++;
|
||||
if (volume > 7)
|
||||
{
|
||||
volume = 7;
|
||||
}
|
||||
am_kv_set("volume", &volume, 1);
|
||||
}
|
||||
if (volume == 7)
|
||||
{
|
||||
char str[] = "音量最大";
|
||||
volPlus.message.tts.data = malloc(sizeof(str));
|
||||
memcpy(volPlus.message.tts.data, str, sizeof(str));
|
||||
volPlus.message.tts.len = sizeof(str);
|
||||
}
|
||||
else
|
||||
{
|
||||
char str[] = "音量加";
|
||||
volPlus.message.tts.data = malloc(sizeof(str));
|
||||
memcpy(volPlus.message.tts.data, str, sizeof(str));
|
||||
volPlus.message.tts.len = sizeof(str);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
char str[] = "音量加";
|
||||
volPlus.message.tts.data = malloc(sizeof(str));
|
||||
memcpy(volPlus.message.tts.data, str, sizeof(str));
|
||||
volPlus.message.tts.len = sizeof(str);
|
||||
}
|
||||
if (pdTRUE != xQueueSend(audioQueueHandle, &volPlus, 0))
|
||||
{
|
||||
DBG("key1 off send audio fail");
|
||||
}
|
||||
break;
|
||||
}
|
||||
case KEY2_MESSAGE:
|
||||
{
|
||||
audioQueueData volMinus = {0};
|
||||
volMinus.playType = TTS_PLAY;
|
||||
volMinus.priority = MONEY_PLAY;
|
||||
volume = 4;
|
||||
ret = am_kv_get("volume", &volume, 1);
|
||||
if (ret > 0)
|
||||
{
|
||||
if (volume > 1)
|
||||
{
|
||||
volume--;
|
||||
if (volume < 1)
|
||||
{
|
||||
volume = 1;
|
||||
}
|
||||
am_kv_set("volume", &volume, 1);
|
||||
}
|
||||
if (volume == 1)
|
||||
{
|
||||
char str[] = "音量最小";
|
||||
volMinus.message.tts.data = malloc(sizeof(str));
|
||||
memcpy(volMinus.message.tts.data, str, sizeof(str));
|
||||
volMinus.message.tts.len = sizeof(str);
|
||||
}
|
||||
else
|
||||
{
|
||||
char str[] = "音量减";
|
||||
volMinus.message.tts.data = malloc(sizeof(str));
|
||||
memcpy(volMinus.message.tts.data, str, sizeof(str));
|
||||
volMinus.message.tts.len = sizeof(str);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
char str[] = "音量减";
|
||||
volMinus.message.tts.data = malloc(sizeof(str));
|
||||
memcpy(volMinus.message.tts.data, str, sizeof(str));
|
||||
volMinus.message.tts.len = sizeof(str);
|
||||
}
|
||||
if (pdTRUE != xQueueSend(audioQueueHandle, &volMinus, 0))
|
||||
{
|
||||
DBG("key1 off send audio fail");
|
||||
}
|
||||
break;
|
||||
}
|
||||
case PWR_MESSAGE:
|
||||
{
|
||||
if (pdFALSE != xTimerIsTimerActive(timerHandlePower))
|
||||
{
|
||||
xTimerStop(timerHandlePower, 5000);
|
||||
uint16_t vbat = getVbat();
|
||||
audioQueueData currentPower = {0};
|
||||
currentPower.priority = MONEY_PLAY;
|
||||
currentPower.playType = TTS_PLAY;
|
||||
if (vbat > 4000)
|
||||
{
|
||||
char str[] = "当前电量高";
|
||||
currentPower.message.tts.data = malloc(sizeof(str));
|
||||
memcpy(currentPower.message.tts.data, str, sizeof(str));
|
||||
currentPower.message.tts.len = sizeof(str);
|
||||
}
|
||||
else if (vbat > 3700 && vbat < 4000)
|
||||
{
|
||||
char str[] = "当前电量中";
|
||||
currentPower.message.tts.data = malloc(sizeof(str));
|
||||
memcpy(currentPower.message.tts.data, str, sizeof(str));
|
||||
currentPower.message.tts.len = sizeof(str);
|
||||
}
|
||||
else
|
||||
{
|
||||
char str[] = "当前电量低";
|
||||
currentPower.message.tts.data = malloc(sizeof(str));
|
||||
memcpy(currentPower.message.tts.data, str, sizeof(str));
|
||||
currentPower.message.tts.len = sizeof(str);
|
||||
}
|
||||
if (pdTRUE != xQueueSend(audioQueueHandle, ¤tPower, 0))
|
||||
{
|
||||
DBG("power off send audio fail");
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
void key_pad_init(void)
|
||||
{
|
||||
if (timerHandlePower == NULL)
|
||||
{
|
||||
timerHandlePower = xTimerCreate("test", 3000, false, NULL, timerCb);
|
||||
}
|
||||
if (timerHandlePowerOff == NULL)
|
||||
{
|
||||
timerHandlePowerOff = xTimerCreate("test", 2000, false, NULL, timerCb);
|
||||
}
|
||||
|
||||
padKeyEventQueueHandle = xQueueCreate(6, sizeof(padkeyQueueMsg_t));
|
||||
|
||||
APmuWakeupPadSettings_t wakeupPadSetting;
|
||||
wakeupPadSetting.negEdgeEn = true;
|
||||
wakeupPadSetting.posEdgeEn = false;
|
||||
wakeupPadSetting.pullDownEn = false;
|
||||
wakeupPadSetting.pullUpEn = true;
|
||||
apmuSetWakeupPadCfg(WAKEUP_PAD_3, true, &wakeupPadSetting); // enable wakeup pad 3
|
||||
NVIC_EnableIRQ(PadWakeup3_IRQn);
|
||||
|
||||
set_pad_wakeup_callback(padkeyIsrCb);
|
||||
pwrKeyDly_t pwrKeyDlyCfg;
|
||||
pwrKeyDlyCfg.longPressTimeout = 3000;
|
||||
pwrKeyDlyCfg.repeatTimeout = 3000;
|
||||
pwrKeyInit(PWRKEY_WAKEUP_LOWACTIVE_MODE, true, pwrKeyDlyCfg, pwrkeyStatusCb);
|
||||
|
||||
//目前云喇叭开发板上的key1用的是gpio,所以暂时作为gpio中断来使用,agpio休眠时仅可保持电平,不可用于中断,后续设计改为wakeup pad
|
||||
PadConfig_t padConfig;
|
||||
PAD_getDefaultConfig(&padConfig);
|
||||
padConfig.mux = PAD_MUX_ALT0;
|
||||
PAD_setPinConfig(46, &padConfig);
|
||||
XIC_SetVector(PXIC1_GPIO_IRQn, GPIO_ISR);
|
||||
XIC_EnableIRQ(PXIC1_GPIO_IRQn);
|
||||
GpioPinConfig_t config;
|
||||
config.pinDirection = GPIO_DIRECTION_INPUT;
|
||||
config.misc.interruptConfig = GPIO_INTERRUPT_RISING_EDGE;
|
||||
GPIO_pinConfig(BUTTON_GPIO_INSTANCE, BUTTON_GPIO_PIN, &config);
|
||||
xTaskCreate(padKeyTask, "", 256, NULL, 20, NULL);
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
|
||||
#include "gpio.h"
|
||||
#include "pad.h"
|
||||
#include "slpman.h"
|
||||
#include "apmu_external.h"
|
||||
#include "common_api.h"
|
||||
#include "charge_management.h"
|
||||
#include "mqttStatus.h"
|
||||
#include "led_task.h"
|
||||
BOOL g_green_led_status = false;
|
||||
BOOL g_red_led_status = false;
|
||||
BOOL g_blue_led_status = false;
|
||||
#define GREEN_CTRL(level) \
|
||||
do \
|
||||
{ \
|
||||
GPIO_pinWrite(LED_GREEN_PORT, 1 << LED_GREEN_PIN, level << LED_GREEN_PIN); \
|
||||
} while (0);
|
||||
#define RED_CTRL(level) \
|
||||
do \
|
||||
{ \
|
||||
GPIO_pinWrite(LED_RED_PORT, 1 << LED_RED_PIN, level << LED_RED_PIN); \
|
||||
} while (0);
|
||||
#define BLUE_CTRL(level) \
|
||||
do \
|
||||
{ \
|
||||
GPIO_pinWrite(LED_BLUE_PORT, 1 << LED_BLUE_PIN, level << LED_BLUE_PIN); \
|
||||
} while (0);
|
||||
|
||||
static void led_task(void *param)
|
||||
{
|
||||
DBG("entry this func");
|
||||
slpManAONIOPowerOn();
|
||||
PadConfig_t padConfig;
|
||||
PAD_getDefaultConfig(&padConfig);
|
||||
padConfig.mux = PAD_MUX_ALT0;
|
||||
PAD_setPinConfig(LED_GREEN_PAD, &padConfig);
|
||||
PAD_setPinConfig(LED_RED_PAD, &padConfig);
|
||||
PAD_setPinConfig(LED_BLUE_PAD, &padConfig);
|
||||
GpioPinConfig_t gpioConfig;
|
||||
gpioConfig.pinDirection = GPIO_DIRECTION_OUTPUT;
|
||||
gpioConfig.misc.initOutput = 0;
|
||||
|
||||
uint8_t ledHandler = 0xff;
|
||||
slpManApplyPlatVoteHandle("ledSLP1Vote",&ledHandler);
|
||||
GPIO_pinConfig(LED_GREEN_PORT, LED_GREEN_PIN, &gpioConfig);
|
||||
GPIO_pinConfig(LED_RED_PORT, LED_RED_PIN, &gpioConfig);
|
||||
GPIO_pinConfig(LED_BLUE_PORT, LED_BLUE_PIN, &gpioConfig);
|
||||
while (1)
|
||||
{
|
||||
|
||||
if (!getNetStatus())
|
||||
{
|
||||
slpManPlatVoteDisableSleep(ledHandler, SLP_SLP1_STATE);
|
||||
GREEN_CTRL(1);
|
||||
BLUE_CTRL(0);
|
||||
RED_CTRL(0);
|
||||
g_green_led_status = true;
|
||||
g_red_led_status = false;
|
||||
g_blue_led_status = false;
|
||||
slpManPlatVoteEnableSleep(ledHandler, SLP_SLP1_STATE);
|
||||
|
||||
vTaskDelay(500);
|
||||
|
||||
slpManPlatVoteDisableSleep(ledHandler, SLP_SLP1_STATE);
|
||||
GREEN_CTRL(0);
|
||||
BLUE_CTRL(0);
|
||||
RED_CTRL(0);
|
||||
g_green_led_status = false;
|
||||
g_red_led_status = false;
|
||||
g_blue_led_status = false;
|
||||
slpManPlatVoteEnableSleep(ledHandler, SLP_SLP1_STATE);
|
||||
vTaskDelay(500);
|
||||
}
|
||||
else if ((usb_portmon_vbuspad_level() == 1))
|
||||
{
|
||||
slpManPlatVoteDisableSleep(ledHandler, SLP_SLP1_STATE);
|
||||
GREEN_CTRL(0);
|
||||
BLUE_CTRL(0);
|
||||
RED_CTRL(1);
|
||||
g_green_led_status = false;
|
||||
g_red_led_status = true;
|
||||
g_blue_led_status = false;
|
||||
slpManPlatVoteEnableSleep(ledHandler, SLP_SLP1_STATE);
|
||||
vTaskDelay(500);
|
||||
}
|
||||
else if (getNetStatus() && !getServerStatus())
|
||||
{
|
||||
slpManPlatVoteDisableSleep(ledHandler, SLP_SLP1_STATE);
|
||||
GREEN_CTRL(0);
|
||||
BLUE_CTRL(1);
|
||||
RED_CTRL(0);
|
||||
g_green_led_status = false;
|
||||
g_red_led_status = false;
|
||||
g_blue_led_status = true;
|
||||
slpManPlatVoteEnableSleep(ledHandler, SLP_SLP1_STATE);
|
||||
vTaskDelay(1000);
|
||||
}
|
||||
else if (getServerStatus())
|
||||
{
|
||||
slpManPlatVoteDisableSleep(ledHandler, SLP_SLP1_STATE);
|
||||
GREEN_CTRL(0);
|
||||
BLUE_CTRL(1);
|
||||
RED_CTRL(0);
|
||||
g_green_led_status = false;
|
||||
g_red_led_status = false;
|
||||
g_blue_led_status = true;
|
||||
slpManPlatVoteEnableSleep(ledHandler, SLP_SLP1_STATE);
|
||||
vTaskDelay(1000);
|
||||
}
|
||||
}
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
void led_task_init(void)
|
||||
{
|
||||
xTaskCreate(led_task, "", 256, NULL, 20, NULL);
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
#include "commontypedef.h"
|
||||
#include "common_api.h"
|
||||
#include "cms_api.h"
|
||||
#include "ps_lib_api.h"
|
||||
static void usb_serial_input_dummy_cb(uint8_t channel, uint8_t *input, uint32_t len)
|
||||
{
|
||||
DBG("usb serial get %d byte, test mode, send back", len);
|
||||
DBG("usb serial get %s", input);
|
||||
|
||||
if (strcmp("AT+CLIENTID?\r\n", (char*)input) == 0)
|
||||
{
|
||||
char clientId[32] = {0};
|
||||
int ret = am_kv_get("clientId", clientId, 16);
|
||||
if(ret > 0 )
|
||||
{
|
||||
usb_serial_output(channel, clientId, strlen(clientId));
|
||||
}
|
||||
else
|
||||
{
|
||||
usb_serial_output(channel, "OK", strlen("OK"));
|
||||
}
|
||||
}
|
||||
else if (strstr((char*)input, "AT+CLIENTID=") != NULL)
|
||||
{
|
||||
char *flag = NULL;
|
||||
flag = strstr((char*)input, "=");
|
||||
if(flag != NULL)
|
||||
{
|
||||
flag++;
|
||||
char *flag2 = NULL;
|
||||
flag2 = strstr(flag, "\r\n");
|
||||
if (flag2 != NULL)
|
||||
{
|
||||
int ret = am_kv_set("clientId", flag, strlen(flag) - 2);
|
||||
usb_serial_output(channel, "OK", strlen("OK"));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
else if (strcmp("AT+USERNAME?\r\n", (char*)input) == 0)
|
||||
{
|
||||
int ret = 0;
|
||||
char name[32] = {0};
|
||||
ret = am_kv_get("username", name, 31);
|
||||
if (ret > 0)
|
||||
{
|
||||
usb_serial_output(channel, name, strlen(name));
|
||||
}
|
||||
else
|
||||
{
|
||||
usb_serial_output(channel, "OK", strlen("OK"));
|
||||
}
|
||||
}
|
||||
else if (strstr((char*)input, "AT+USERNAME=") != NULL)
|
||||
{
|
||||
char *flag = NULL;
|
||||
flag = strstr((char*)input, "=");
|
||||
if(flag != NULL)
|
||||
{
|
||||
flag++;
|
||||
char *flag2 = NULL;
|
||||
flag2 = strstr(flag, "\r\n");
|
||||
if (flag2 != NULL)
|
||||
{
|
||||
int ret = am_kv_set("username", flag, strlen(flag) - 2);
|
||||
usb_serial_output(channel, "OK", strlen("OK"));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
else if (strcmp("AT+PASSWORD?\r\n", (char*)input) == 0)
|
||||
{
|
||||
int ret = 0;
|
||||
char name[32] = {0};
|
||||
ret = am_kv_get("password", name, 31);
|
||||
if (ret > 0)
|
||||
{
|
||||
usb_serial_output(channel, name, strlen(name));
|
||||
}
|
||||
else
|
||||
{
|
||||
usb_serial_output(channel, "OK", strlen("OK"));
|
||||
}
|
||||
}
|
||||
else if (strstr((char*)input, "AT+PASSWORD=") != NULL)
|
||||
{
|
||||
char *flag = NULL;
|
||||
flag = strstr((char*)input, "=");
|
||||
if(flag != NULL)
|
||||
{
|
||||
flag++;
|
||||
char *flag2 = NULL;
|
||||
flag2 = strstr(flag, "\r\n");
|
||||
if (flag2 != NULL)
|
||||
{
|
||||
int ret = am_kv_set("password", flag, strlen(flag) - 2);
|
||||
usb_serial_output(channel, "OK", strlen("OK"));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
void usb_data_init(void)
|
||||
{
|
||||
DBG("this hw demo1");
|
||||
set_usb_serial_input_callback(usb_serial_input_dummy_cb);
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
local TARGET_NAME = "cloud_speaker"
|
||||
local LIB_DIR = "$(buildir)/".. TARGET_NAME .. "/"
|
||||
local LIB_NAME = "lib" .. TARGET_NAME .. ".a "
|
||||
includes(SDK_TOP .. "/thirdparty/audio_decoder")
|
||||
target(TARGET_NAME)
|
||||
local LIB_DIR = "$(buildir)/mqttclient/"
|
||||
set_kind("static")
|
||||
set_targetdir(LIB_DIR)
|
||||
add_deps("audio_decoder")
|
||||
add_defines("MQTT_TASK",{public = true})
|
||||
|
||||
includes(SDK_TOP .. "/thirdparty/mqtt")
|
||||
add_deps("mqtt")
|
||||
includes(SDK_TOP .. "/thirdparty/cJSON")
|
||||
-- --加入代码和头文件
|
||||
add_includedirs(SDK_TOP .. "/thirdparty/mqtt/MQTTClient-C/src",{public = true})
|
||||
add_files(SDK_TOP .. "/thirdparty/mqtt/MQTTClient-C/src/*.c",{public = true})
|
||||
add_includedirs(SDK_TOP .. "/PLAT/core/tts/include/16k_lite_ver",{public = true})
|
||||
--加入自己代码和头文件
|
||||
add_includedirs("/inc",{public = true})
|
||||
add_files("/src/*.c",{public = true})
|
||||
|
||||
--可以继续增加add_includedirs和add_files
|
||||
add_includedirs("../../thirdparty/fal/inc",{public = true})
|
||||
add_includedirs("../../thirdparty/flashdb/inc",{public = true})
|
||||
add_includedirs("../../thirdparty/am_kv/inc",{public = true})
|
||||
add_files("../../thirdparty/fal/src/*.c",{public = true})
|
||||
add_files("../../thirdparty/flashdb/src/*.c",{public = true})
|
||||
add_files("../../thirdparty/am_kv/src/*.c",{public = true})
|
||||
--自动链接
|
||||
LIB_USER = LIB_USER .. SDK_TOP .. LIB_DIR .. LIB_NAME .. " "
|
||||
LIB_USER = LIB_USER .. SDK_TOP .. "/PLAT/core/lib/libaisound50_16K_lite_beta.a "
|
||||
--甚至可以加入自己的库
|
||||
target_end()
|
||||
Reference in New Issue
Block a user