summaryrefslogtreecommitdiff
path: root/app/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'app/main.c')
-rw-r--r--app/main.c128
1 files changed, 14 insertions, 114 deletions
diff --git a/app/main.c b/app/main.c
index 352d766..3ac4ab0 100644
--- a/app/main.c
+++ b/app/main.c
@@ -60,7 +60,8 @@
#include "indicate/indicate_modes_task.h"
#include "tsl_user.h"
#include "time/time.h"
-#include "stm32f0xx_usart.h"
+#include "platform/platform.h"
+#include "unistd.h"
/* Private typedefs ----------------------------------------------------------*/
@@ -81,117 +82,12 @@
/* Private functions prototype ---------------------------------------------- */
-static void USART1Init(void)
-{
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
- RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
- GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_1);
- GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_1);
- GPIO_InitTypeDef GPIO_InitStructure;
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_Level_3;
- GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
- GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;
- GPIO_Init(GPIOA, &GPIO_InitStructure);
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
- GPIO_Init(GPIOA, &GPIO_InitStructure);
- USART_InitTypeDef usart_init = {0};
- usart_init.USART_BaudRate = 115200;
- usart_init.USART_WordLength = USART_WordLength_8b;
- usart_init.USART_StopBits = USART_StopBits_1;
- usart_init.USART_Parity = USART_Parity_No;
- usart_init.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
- usart_init.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
- USART_Init(USART1, &usart_init);
- USART_Cmd(USART1, ENABLE);
-}
-
-static void USART4Init(void)
-{
- RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART4, ENABLE);
- RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
- GPIO_PinAFConfig(GPIOA, GPIO_PinSource0, GPIO_AF_4);
- GPIO_PinAFConfig(GPIOA, GPIO_PinSource1, GPIO_AF_4);
- GPIO_InitTypeDef GPIO_InitStructure;
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_Level_3;
- GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
- GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;
- GPIO_Init(GPIOA, &GPIO_InitStructure);
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
- GPIO_Init(GPIOA, &GPIO_InitStructure);
- USART_InitTypeDef usart_init = {0};
- usart_init.USART_BaudRate = 9600;
- usart_init.USART_WordLength = USART_WordLength_8b;
- usart_init.USART_StopBits = USART_StopBits_1;
- usart_init.USART_Parity = USART_Parity_No;
- usart_init.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
- usart_init.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
- USART_Init(USART4, &usart_init);
- USART_Cmd(USART4, ENABLE);
-}
-
-static void WIFI_IO_GPIOInit(void)
-{
- RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
- RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);
- GPIO_InitTypeDef GPIO_InitStructure;
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_Level_3;
- GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
- GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;
- GPIO_Init(GPIOA, &GPIO_InitStructure);
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
- GPIO_Init(GPIOB, &GPIO_InitStructure);
- GPIO_SetBits(GPIOB, GPIO_Pin_0); // WIFI_EN
- GPIO_ResetBits(GPIOA, GPIO_Pin_15); // WIFI_IO0
-}
-
-static void USART3Init(void)
-{
- RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
- RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);
- GPIO_PinAFConfig(GPIOB, GPIO_PinSource1, GPIO_AF_4);
- GPIO_PinAFConfig(GPIOB, GPIO_PinSource10, GPIO_AF_4);
- GPIO_PinAFConfig(GPIOB, GPIO_PinSource11, GPIO_AF_4);
- GPIO_PinAFConfig(GPIOB, GPIO_PinSource13, GPIO_AF_4);
- GPIO_InitTypeDef GPIO_InitStructure;
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_Level_3;
- GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
- GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;
- GPIO_Init(GPIOB, &GPIO_InitStructure);
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
- GPIO_Init(GPIOB, &GPIO_InitStructure);
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
- GPIO_Init(GPIOB, &GPIO_InitStructure);
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;
- GPIO_Init(GPIOB, &GPIO_InitStructure);
- USART_InitTypeDef usart_init = {0};
- usart_init.USART_BaudRate = 115200;
- usart_init.USART_WordLength = USART_WordLength_8b;
- usart_init.USART_StopBits = USART_StopBits_1;
- usart_init.USART_Parity = USART_Parity_No;
- usart_init.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
- usart_init.USART_HardwareFlowControl = USART_HardwareFlowControl_RTS_CTS;
- USART_Init(USART3, &usart_init);
- USART_Cmd(USART3, ENABLE);
-}
-
// ----------------------------------------------------------------------------
// Инициализация до создания задач
// ----------------------------------------------------------------------------
void InitAll ( void )
{
- SystemInit();
- WIFI_IO_GPIOInit();
- USART1Init();
- USART3Init();
- USART4Init();
+ PlatformInit();
InitLTimers();
LightSensorInit();
NixieDriverInit();
@@ -208,14 +104,18 @@ void InitAll ( void )
static void TestUart(void *arg)
{
(void) arg;
+ const int wifi_fd = PlatformGetWiFiFileDescriptor();
while (1) {
- if (USART3->ISR & USART_ISR_RXNE) {
- const uint16_t data = USART_ReceiveData(USART3);
- USART_SendData(USART1, data);
- }
- if (USART1->ISR & USART_ISR_RXNE) {
- const uint16_t data = USART_ReceiveData(USART1);
- USART_SendData(USART3, data);
+ char buf[50];
+ const ssize_t rret = read(wifi_fd, buf, sizeof(buf));
+ if (rret > 0) {
+ const size_t rsize = rret;
+ for (size_t written = 0; written < rsize; written++) {
+ const ssize_t wret = write(STDOUT_FILENO, buf, rsize - written);
+ if (wret > 0) {
+ written += (size_t)wret;
+ }
+ }
}
}
}