diff --git a/bsp/stm32/libraries/HAL_Drivers/drv_gpio.c b/bsp/stm32/libraries/HAL_Drivers/drv_gpio.c index 9824d3eb2f..57442f2739 100644 --- a/bsp/stm32/libraries/HAL_Drivers/drv_gpio.c +++ b/bsp/stm32/libraries/HAL_Drivers/drv_gpio.c @@ -6,6 +6,7 @@ * Change Logs: * Date Author Notes * 2018-11-06 balanceTWK first version + * 2019-04-23 WillianChan Fix GPIO serial number disorder */ #include @@ -153,65 +154,65 @@ static const struct pin_index pins[] = __STM32_PIN(120, H, 8), __STM32_PIN(121, H, 9), __STM32_PIN(122, H, 10), - __STM32_PIN(124, H, 11), - __STM32_PIN(125, H, 12), - __STM32_PIN(126, H, 13), - __STM32_PIN(127, H, 14), - __STM32_PIN(128, H, 15), + __STM32_PIN(123, H, 11), + __STM32_PIN(124, H, 12), + __STM32_PIN(125, H, 13), + __STM32_PIN(126, H, 14), + __STM32_PIN(127, H, 15), #endif #ifdef GPIOI - __STM32_PIN(129, I, 0), - __STM32_PIN(130, I, 1), - __STM32_PIN(131, I, 2), - __STM32_PIN(132, I, 3), - __STM32_PIN(133, I, 4), - __STM32_PIN(134, I, 5), - __STM32_PIN(135, I, 6), - __STM32_PIN(136, I, 7), - __STM32_PIN(137, I, 8), - __STM32_PIN(138, I, 9), - __STM32_PIN(139, I, 10), - __STM32_PIN(140, I, 11), - __STM32_PIN(141, I, 12), - __STM32_PIN(142, I, 13), - __STM32_PIN(143, I, 14), - __STM32_PIN(144, I, 15), + __STM32_PIN(128, I, 0), + __STM32_PIN(129, I, 1), + __STM32_PIN(130, I, 2), + __STM32_PIN(131, I, 3), + __STM32_PIN(132, I, 4), + __STM32_PIN(133, I, 5), + __STM32_PIN(134, I, 6), + __STM32_PIN(135, I, 7), + __STM32_PIN(136, I, 8), + __STM32_PIN(137, I, 9), + __STM32_PIN(138, I, 10), + __STM32_PIN(139, I, 11), + __STM32_PIN(140, I, 12), + __STM32_PIN(141, I, 13), + __STM32_PIN(142, I, 14), + __STM32_PIN(143, I, 15), #endif #ifdef GPIOJ - __STM32_PIN(145, J, 0), - __STM32_PIN(146, J, 1), - __STM32_PIN(147, J, 2), - __STM32_PIN(148, J, 3), - __STM32_PIN(149, J, 4), - __STM32_PIN(150, J, 5), - __STM32_PIN(151, J, 6), - __STM32_PIN(152, J, 7), - __STM32_PIN(153, J, 8), - __STM32_PIN(154, J, 9), - __STM32_PIN(155, J, 10), - __STM32_PIN(156, J, 11), - __STM32_PIN(157, J, 12), - __STM32_PIN(158, J, 13), - __STM32_PIN(159, J, 14), - __STM32_PIN(160, J, 15), + __STM32_PIN(144, J, 0), + __STM32_PIN(145, J, 1), + __STM32_PIN(146, J, 2), + __STM32_PIN(147, J, 3), + __STM32_PIN(148, J, 4), + __STM32_PIN(149, J, 5), + __STM32_PIN(150, J, 6), + __STM32_PIN(151, J, 7), + __STM32_PIN(152, J, 8), + __STM32_PIN(153, J, 9), + __STM32_PIN(154, J, 10), + __STM32_PIN(155, J, 11), + __STM32_PIN(156, J, 12), + __STM32_PIN(157, J, 13), + __STM32_PIN(158, J, 14), + __STM32_PIN(159, J, 15), #endif #ifdef GPIOK - __STM32_PIN(161, K, 0), - __STM32_PIN(162, K, 1), - __STM32_PIN(163, K, 2), - __STM32_PIN(164, K, 3), - __STM32_PIN(165, K, 4), - __STM32_PIN(166, K, 5), - __STM32_PIN(167, K, 6), - __STM32_PIN(168, K, 7), - __STM32_PIN(169, K, 8), - __STM32_PIN(170, K, 9), - __STM32_PIN(171, K, 10), - __STM32_PIN(172, K, 11), - __STM32_PIN(173, K, 12), - __STM32_PIN(174, K, 13), - __STM32_PIN(175, K, 14), - __STM32_PIN(176, K, 15), + __STM32_PIN(160, K, 0), + __STM32_PIN(161, K, 1), + __STM32_PIN(162, K, 2), + __STM32_PIN(163, K, 3), + __STM32_PIN(164, K, 4), + __STM32_PIN(165, K, 5), + __STM32_PIN(166, K, 6), + __STM32_PIN(167, K, 7), + __STM32_PIN(168, K, 8), + __STM32_PIN(169, K, 9), + __STM32_PIN(170, K, 10), + __STM32_PIN(171, K, 11), + __STM32_PIN(172, K, 12), + __STM32_PIN(173, K, 13), + __STM32_PIN(174, K, 14), + __STM32_PIN(175, K, 15), #endif }; diff --git a/bsp/stm32/libraries/HAL_Drivers/drv_pwm.c b/bsp/stm32/libraries/HAL_Drivers/drv_pwm.c index 6f1c123a56..a6835e682f 100644 --- a/bsp/stm32/libraries/HAL_Drivers/drv_pwm.c +++ b/bsp/stm32/libraries/HAL_Drivers/drv_pwm.c @@ -415,13 +415,13 @@ static void pwm_get_channel(void) stm32_pwm_obj[PWM1_INDEX].channel |= 1 << 0; #endif #ifdef BSP_USING_PWM1_CH2 - stm32_pwm_obj[PWM1_INDEX].channel |= 1 << 2; + stm32_pwm_obj[PWM1_INDEX].channel |= 1 << 1; #endif #ifdef BSP_USING_PWM1_CH3 - stm32_pwm_obj[PWM1_INDEX].channel |= 1 << 3; + stm32_pwm_obj[PWM1_INDEX].channel |= 1 << 2; #endif #ifdef BSP_USING_PWM1_CH4 - stm32_pwm_obj[PWM1_INDEX].channel |= 1 << 4; + stm32_pwm_obj[PWM1_INDEX].channel |= 1 << 3; #endif #ifdef BSP_USING_PWM2_CH1 stm32_pwm_obj[PWM2_INDEX].channel |= 1 << 0; diff --git a/bsp/stm32/stm32f469-st-disco/board/Kconfig b/bsp/stm32/stm32f469-st-disco/board/Kconfig index 3e5272eb8b..5615ce827c 100644 --- a/bsp/stm32/stm32f469-st-disco/board/Kconfig +++ b/bsp/stm32/stm32f469-st-disco/board/Kconfig @@ -26,6 +26,19 @@ menu "Onboard Peripheral Drivers" select FAL_USING_SFUD_PORT default n + config BSP_USING_TOUCH + bool "Enable TOUCH" + select BSP_USING_I2C1 + default n + if BSP_USING_TOUCH + config BSP_TOUCH_INT_PIN + int "Touch interrupt pin" + default 149 + config BSP_I2C_NAME + string "I2C Bus Name" + default "i2c1" + endif + config BSP_MOUNT_QSPI_WITH_LFS bool "Mount QSPI flash to / with little fs" depends on BSP_USING_QSPI_FLASH @@ -55,6 +68,24 @@ menu "On-chip Peripheral Drivers" depends on BSP_USING_UART3 && RT_SERIAL_USING_DMA default n endif + + menuconfig BSP_USING_I2C1 + bool "Enable I2C1 BUS (software simulation)" + default n + select RT_USING_I2C + select RT_USING_I2C_BITOPS + select RT_USING_PIN + if BSP_USING_I2C1 + comment "Notice: PB8 --> 24; PB9 --> 25" + config BSP_I2C1_SCL_PIN + int "I2C1 scl pin number" + range 1 176 + default 24 + config BSP_I2C1_SDA_PIN + int "I2C1 sda pin number" + range 1 176 + default 25 + endif config BSP_USING_QSPI bool "Enable QSPI BUS" diff --git a/bsp/stm32/stm32f469-st-disco/board/SConscript b/bsp/stm32/stm32f469-st-disco/board/SConscript index c3801987c2..573195ff00 100644 --- a/bsp/stm32/stm32f469-st-disco/board/SConscript +++ b/bsp/stm32/stm32f469-st-disco/board/SConscript @@ -20,6 +20,9 @@ if GetDepend(['PKG_USING_FAL']): if GetDepend(['BSP_USING_LCD_OTM8009A']): src += Glob('ports/drv_lcd_otm8009a.c') + +if GetDepend(['BSP_USING_TOUCH']): + src += Glob('ports/touch/*.c') path = [cwd] path += [cwd + '/CubeMX_Config/Inc'] diff --git a/bsp/stm32/stm32f469-st-disco/board/ports/touch/SConscript b/bsp/stm32/stm32f469-st-disco/board/ports/touch/SConscript new file mode 100644 index 0000000000..f65574f8c4 --- /dev/null +++ b/bsp/stm32/stm32f469-st-disco/board/ports/touch/SConscript @@ -0,0 +1,9 @@ +from building import * + +cwd = GetCurrentDir() +src = Glob('*.c') +CPPPATH = [cwd, str(Dir('#'))] + +group = DefineGroup('touch', src, depend = ['BSP_USING_TOUCH'], CPPPATH = CPPPATH) + +Return('group') diff --git a/bsp/stm32/stm32f469-st-disco/board/ports/touch/drv_touch.c b/bsp/stm32/stm32f469-st-disco/board/ports/touch/drv_touch.c new file mode 100644 index 0000000000..1ff29544ff --- /dev/null +++ b/bsp/stm32/stm32f469-st-disco/board/ports/touch/drv_touch.c @@ -0,0 +1,196 @@ +/* + * Copyright (c) 2006-2018, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2018-02-08 Zhangyihong the first version + */ + +#include "drv_touch.h" +#include +#ifdef BSP_USING_TOUCH +#ifdef PKG_USING_GUIENGINE +#include +#include +#elif defined(PKG_USING_LITTLEVGL2RTT) +#include +#endif +#define BSP_TOUCH_SAMPLE_HZ (50) + +#define DBG_ENABLE +#define DBG_SECTION_NAME "TOUCH" +#define DBG_LEVEL DBG_LOG +#define DBG_COLOR +#include + +static rt_list_t driver_list; + + +void rt_touch_drivers_register(touch_drv_t drv) +{ + rt_list_insert_before(&driver_list, &drv->list); +} + +static void post_down_event(rt_uint16_t x, rt_uint16_t y, rt_tick_t ts) +{ +#ifdef PKG_USING_GUIENGINE + struct rtgui_event_mouse emouse; + + emouse.parent.sender = RT_NULL; + emouse.wid = RT_NULL; + + emouse.parent.type = RTGUI_EVENT_MOUSE_BUTTON; + emouse.button = RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_DOWN; + emouse.x = x; + emouse.y = y; + emouse.ts = rt_tick_get(); + emouse.id = ts; + rtgui_server_post_event(&emouse.parent, sizeof(emouse)); +#elif defined(PKG_USING_LITTLEVGL2RTT) + littlevgl2rtt_send_input_event(x, y, LITTLEVGL2RTT_INPUT_DOWN); +#endif +} + +static void post_motion_event(rt_uint16_t x, rt_uint16_t y, rt_tick_t ts) +{ +#ifdef PKG_USING_GUIENGINE + struct rtgui_event_mouse emouse; + + emouse.parent.sender = RT_NULL; + emouse.wid = RT_NULL; + + emouse.button = RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_DOWN; + emouse.parent.type = RTGUI_EVENT_MOUSE_MOTION; + emouse.x = x; + emouse.y = y; + emouse.ts = rt_tick_get(); + emouse.id = ts; + rtgui_server_post_event(&emouse.parent, sizeof(emouse)); +#elif defined(PKG_USING_LITTLEVGL2RTT) + littlevgl2rtt_send_input_event(x, y, LITTLEVGL2RTT_INPUT_MOVE); +#endif +} + +static void post_up_event(rt_uint16_t x, rt_uint16_t y, rt_tick_t ts) +{ +#ifdef PKG_USING_GUIENGINE + struct rtgui_event_mouse emouse; + + emouse.parent.sender = RT_NULL; + emouse.wid = RT_NULL; + + emouse.parent.type = RTGUI_EVENT_MOUSE_BUTTON; + emouse.button = RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_UP; + emouse.x = x; + emouse.y = y; + emouse.ts = rt_tick_get(); + emouse.id = ts; + rtgui_server_post_event(&emouse.parent, sizeof(emouse)); +#elif defined(PKG_USING_LITTLEVGL2RTT) + littlevgl2rtt_send_input_event(x, y, LITTLEVGL2RTT_INPUT_MOVE); +#endif +} + +static void touch_thread_entry(void *parameter) +{ + touch_drv_t touch = (touch_drv_t)parameter; + struct touch_message msg; + rt_tick_t emouse_id = 0; + touch->ops->isr_enable(RT_TRUE); + while (1) + { + if (rt_sem_take(touch->isr_sem, 10) != RT_EOK) + { + continue; + } + + while(touch->ops->read_point(&msg) == RT_EOK) + { + switch (msg.event) + { + case TOUCH_EVENT_UP: + post_up_event(msg.x, msg.y, emouse_id); + break; + case TOUCH_EVENT_DOWN: + emouse_id = rt_tick_get(); + post_down_event(msg.x, msg.y, emouse_id); + break; + case TOUCH_EVENT_MOVE: + post_motion_event(msg.x, msg.y, emouse_id); + break; + default: + break; + } + rt_thread_delay(RT_TICK_PER_SECOND / BSP_TOUCH_SAMPLE_HZ); + } + touch->ops->isr_enable(RT_TRUE); + } +} + +static int rt_touch_driver_init(void) +{ + rt_list_init(&driver_list); + return 0; +} +INIT_BOARD_EXPORT(rt_touch_driver_init); + +static struct rt_i2c_bus_device *i2c_bus = RT_NULL; +static int rt_touch_thread_init(void) +{ + rt_list_t *l; + touch_drv_t current_driver; + rt_thread_t tid = RT_NULL; + i2c_bus = (struct rt_i2c_bus_device *)rt_device_find(BSP_I2C_NAME); + RT_ASSERT(i2c_bus); + current_driver = RT_NULL; + if (rt_device_open((rt_device_t)i2c_bus, RT_DEVICE_OFLAG_RDWR) != RT_EOK) + return -1; + for (l = driver_list.next; l != &driver_list; l = l->next) + { + if (rt_list_entry(l, struct touch_drivers, list)->probe(i2c_bus)) + { + current_driver = rt_list_entry(l, struct touch_drivers, list); + break; + } + } + if (current_driver == RT_NULL) + { + LOG_E("no touch screen or do not have driver\r\n"); + rt_device_close((rt_device_t)i2c_bus); + return -1; + } + current_driver->ops->init(i2c_bus); + LOG_I("touch screen found driver\r\n"); + tid = rt_thread_create("touch", touch_thread_entry, current_driver, 2048, 27, 20); + if (tid == RT_NULL) + { + current_driver->ops->deinit(); + rt_device_close((rt_device_t)i2c_bus); + return -1; + } + rt_thread_startup(tid); + return 0; +} + +static void touch_init_thread_entry(void *parameter) +{ + rt_touch_thread_init(); +} + +static int touc_bg_init(void) +{ + rt_thread_t tid = RT_NULL; + tid = rt_thread_create("touchi", touch_init_thread_entry, RT_NULL, 2048, 28, 20); + if (tid == RT_NULL) + { + return -1; + } + rt_thread_startup(tid); + return 0; +} +INIT_APP_EXPORT(touc_bg_init); + + +#endif diff --git a/bsp/stm32/stm32f469-st-disco/board/ports/touch/drv_touch.h b/bsp/stm32/stm32f469-st-disco/board/ports/touch/drv_touch.h new file mode 100644 index 0000000000..a8fea21d54 --- /dev/null +++ b/bsp/stm32/stm32f469-st-disco/board/ports/touch/drv_touch.h @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2006-2018, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2018-02-08 Zhangyihong the first version + */ + +#ifndef __DRV_TOUCH_H__ +#define __DRV_TOUCH_H__ + +#include "rtthread.h" +#include "rtdevice.h" + +#define TOUCH_DBG_LEVEL DBG_LOG + +#define IIC_RETRY_NUM 2 + +#define TOUCH_EVENT_UP (0x01) +#define TOUCH_EVENT_DOWN (0x02) +#define TOUCH_EVENT_MOVE (0x03) +#define TOUCH_EVENT_NONE (0x80) + +struct touch_message +{ + rt_uint16_t x; + rt_uint16_t y; + rt_uint8_t event; +}; +typedef struct touch_message *touch_msg_t; + +struct touch_ops +{ + void (* isr_enable)(rt_bool_t); + rt_err_t (* read_point)(touch_msg_t); + void (* init)(struct rt_i2c_bus_device *); + void (* deinit)(void); +}; +typedef struct touch_ops *touch_ops_t; + +struct touch_drivers +{ + rt_list_t list; + unsigned char address; + rt_bool_t (*probe)(struct rt_i2c_bus_device *i2c_bus); + rt_sem_t isr_sem; + touch_ops_t ops; + void *user_data; +}; +typedef struct touch_drivers *touch_drv_t; + +extern void rt_touch_drivers_register(touch_drv_t drv); +#endif diff --git a/bsp/stm32/stm32f469-st-disco/board/ports/touch/drv_touch_ft.c b/bsp/stm32/stm32f469-st-disco/board/ports/touch/drv_touch_ft.c new file mode 100644 index 0000000000..a7e9275441 --- /dev/null +++ b/bsp/stm32/stm32f469-st-disco/board/ports/touch/drv_touch_ft.c @@ -0,0 +1,213 @@ +/* + * Copyright (c) 2006-2018, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2017-08-08 Yang the first version + * 2019-04-23 WillianChan porting to ft6206 + */ + +#include +#include +#include +#include "drv_touch.h" +#include + +#ifdef BSP_USING_TOUCH + +#define DBG_ENABLE +#define DBG_SECTION_NAME "TOUCH.ft" +#define DBG_LEVEL TOUCH_DBG_LEVEL +#define DBG_COLOR +#include + +static struct rt_i2c_bus_device *ft_i2c_bus; +static struct touch_drivers ft_driver; + +static int ft_read(struct rt_i2c_bus_device *i2c_bus, rt_uint8_t addr, rt_uint8_t *buffer, rt_size_t length) +{ + int ret = -1; + int retries = 0; + + struct rt_i2c_msg msgs[] = + { + { + .addr = ft_driver.address, + .flags = RT_I2C_WR, + .len = 1, + .buf = &addr, + }, + { + .addr = ft_driver.address, + .flags = RT_I2C_RD, + .len = length, + .buf = buffer, + }, + }; + + while (retries < IIC_RETRY_NUM) + { + ret = rt_i2c_transfer(i2c_bus, msgs, 2); + if (ret == 2)break; + retries++; + } + + if (retries >= IIC_RETRY_NUM) + { + LOG_E("%s i2c read error: %d", __func__, ret); + return -1; + } + + return ret; +} + +static void ft_write(touch_drv_t driver, struct rt_i2c_bus_device *i2c_bus, rt_uint8_t addr, rt_uint8_t *buffer, rt_size_t length) +{ + rt_uint8_t *send_buffer = rt_malloc(length + 1); + + RT_ASSERT(send_buffer); + + send_buffer[0] = addr; + memcpy(send_buffer + 1, buffer, length); + + struct rt_i2c_msg msgs[] = + { + { + .addr = ft_driver.address, + .flags = RT_I2C_WR, + .len = length + 1, + .buf = send_buffer, + } + }; + + length = rt_i2c_transfer(i2c_bus, msgs, 1); + rt_free(send_buffer); + send_buffer = RT_NULL; +} + +static void ft_isr_enable(rt_bool_t enable) +{ + rt_pin_irq_enable(BSP_TOUCH_INT_PIN, enable); +} + +static void ft_touch_isr(void *parameter) +{ + ft_isr_enable(RT_FALSE); + rt_sem_release(ft_driver.isr_sem); +} + +static rt_err_t ft_read_point(touch_msg_t msg) +{ + int ret = -1; + uint8_t point_num = 0; + static uint8_t s_tp_down = 0; + uint8_t point[6]; + ret = ft_read(ft_i2c_bus, 0x02, &point_num, 1); + if (ret < 0) + { + return RT_ERROR; + } + + if (point_num == 0) + { + if (s_tp_down) + { + s_tp_down = 0; + msg->event = TOUCH_EVENT_UP; + return RT_EOK; + } + msg->event = TOUCH_EVENT_NONE; + return RT_ERROR; + } + + ret = ft_read(ft_i2c_bus, 0x03, point, 6); + if (ret < 0) + { + return RT_ERROR; + } + + msg->y = (point[0]&0x0F) << 8 | point[1]; + msg->x = (point[2]&0x0F) << 8 | point[3]; + + if (s_tp_down) + { + msg->event = TOUCH_EVENT_MOVE; + return RT_EOK; + } + msg->event = TOUCH_EVENT_DOWN; + s_tp_down = 1; + + return RT_EOK; +} + +static void ft_init(struct rt_i2c_bus_device *i2c_bus) +{ + if (ft_i2c_bus == RT_NULL) + { + ft_i2c_bus = i2c_bus; + } + ft_driver.isr_sem = rt_sem_create("ft", 0, RT_IPC_FLAG_FIFO); + RT_ASSERT(ft_driver.isr_sem); + + rt_pin_mode(BSP_TOUCH_INT_PIN, PIN_MODE_INPUT_PULLUP); + rt_pin_attach_irq(BSP_TOUCH_INT_PIN, PIN_IRQ_MODE_FALLING, ft_touch_isr, RT_NULL); + + rt_thread_mdelay(200); +} + +static void ft_deinit(void) +{ + if (ft_driver.isr_sem) + { + rt_sem_delete(ft_driver.isr_sem); + ft_driver.isr_sem = RT_NULL; + } +} + +struct touch_ops ft_ops = +{ + ft_isr_enable, + ft_read_point, + ft_init, + ft_deinit, +}; + +static rt_bool_t ft_probe(struct rt_i2c_bus_device *i2c_bus) +{ + int err = 0; + uint8_t cid = 0xFF; + + ft_i2c_bus = i2c_bus; + /* FT6206 Chip identification register address is 0xA8 */ + err = ft_read(ft_i2c_bus, 0xA8, (uint8_t *)&cid, 1); + if (err < 0) + { + LOG_E("%s failed: %d", __func__, err); + return RT_FALSE; + } + LOG_I("touch CID:0x%02X", cid); + /* FT6206 ID Value is 0x11 */ + if(cid == 0x11) + { + return RT_TRUE; + } + return RT_FALSE; +} + +int ft_driver_register(void) +{ + /* TouchScreen FT6206 Slave I2C address is 0x54 + * 0x54 << 1 = 0x2A + */ + ft_driver.address = 0x2A; + ft_driver.probe = ft_probe; + ft_driver.ops = &ft_ops; + ft_driver.user_data = RT_NULL; + rt_touch_drivers_register(&ft_driver); + return 0; +} +INIT_DEVICE_EXPORT(ft_driver_register); + +#endif diff --git a/bsp/stm32/stm32f469-st-disco/project.ewp b/bsp/stm32/stm32f469-st-disco/project.ewp index 03017d11a6..57079447f6 100644 --- a/bsp/stm32/stm32f469-st-disco/project.ewp +++ b/bsp/stm32/stm32f469-st-disco/project.ewp @@ -2135,6 +2135,9 @@ $PROJ_DIR$\..\libraries\HAL_Drivers\drv_usart.c + + $PROJ_DIR$\..\libraries\HAL_Drivers\drv_soft_i2c.c + $PROJ_DIR$\..\libraries\HAL_Drivers\drv_common.c @@ -2159,6 +2162,15 @@ DeviceDrivers + + $PROJ_DIR$\..\..\..\components\drivers\i2c\i2c_core.c + + + $PROJ_DIR$\..\..\..\components\drivers\i2c\i2c_dev.c + + + $PROJ_DIR$\..\..\..\components\drivers\i2c\i2c-bit-ops.c + $PROJ_DIR$\..\..\..\components\drivers\misc\pin.c @@ -2291,5 +2303,11 @@ $PROJ_DIR$\..\libraries\STM32F4xx_HAL\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_usart.c + + $PROJ_DIR$\..\libraries\STM32F4xx_HAL\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_i2c.c + + + $PROJ_DIR$\..\libraries\STM32F4xx_HAL\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_i2c_ex.c + diff --git a/bsp/stm32/stm32f469-st-disco/project.uvoptx b/bsp/stm32/stm32f469-st-disco/project.uvoptx index 0cb41f3acd..0384f4f5c4 100644 --- a/bsp/stm32/stm32f469-st-disco/project.uvoptx +++ b/bsp/stm32/stm32f469-st-disco/project.uvoptx @@ -408,7 +408,7 @@ Drivers - 0 + 1 0 0 0 @@ -567,6 +567,42 @@ 0 0 0 + ..\..\..\components\drivers\i2c\i2c_core.c + i2c_core.c + 0 + 0 + + + 5 + 30 + 1 + 0 + 0 + 0 + ..\..\..\components\drivers\i2c\i2c_dev.c + i2c_dev.c + 0 + 0 + + + 5 + 31 + 1 + 0 + 0 + 0 + ..\..\..\components\drivers\i2c\i2c-bit-ops.c + i2c-bit-ops.c + 0 + 0 + + + 5 + 32 + 1 + 0 + 0 + 0 ..\..\..\components\drivers\misc\pin.c pin.c 0 @@ -574,7 +610,7 @@ 5 - 30 + 33 1 0 0 @@ -586,7 +622,7 @@ 5 - 31 + 34 1 0 0 @@ -598,7 +634,7 @@ 5 - 32 + 35 1 0 0 @@ -610,7 +646,7 @@ 5 - 33 + 36 1 0 0 @@ -622,7 +658,7 @@ 5 - 34 + 37 1 0 0 @@ -634,7 +670,7 @@ 5 - 35 + 38 1 0 0 @@ -646,7 +682,7 @@ 5 - 36 + 39 1 0 0 @@ -658,7 +694,7 @@ 5 - 37 + 40 1 0 0 @@ -678,7 +714,7 @@ 0 6 - 38 + 41 1 0 0 @@ -690,7 +726,7 @@ 6 - 39 + 42 1 0 0 @@ -702,7 +738,7 @@ 6 - 40 + 43 1 0 0 @@ -714,7 +750,7 @@ 6 - 41 + 44 1 0 0 @@ -726,7 +762,7 @@ 6 - 42 + 45 1 0 0 @@ -738,7 +774,7 @@ 6 - 43 + 46 1 0 0 @@ -750,7 +786,7 @@ 6 - 44 + 47 1 0 0 @@ -762,7 +798,7 @@ 6 - 45 + 48 1 0 0 @@ -774,7 +810,7 @@ 6 - 46 + 49 1 0 0 @@ -786,7 +822,7 @@ 6 - 47 + 50 1 0 0 @@ -798,7 +834,7 @@ 6 - 48 + 51 1 0 0 @@ -810,7 +846,7 @@ 6 - 49 + 52 1 0 0 @@ -822,7 +858,7 @@ 6 - 50 + 53 1 0 0 @@ -834,7 +870,7 @@ 6 - 51 + 54 1 0 0 @@ -846,7 +882,7 @@ 6 - 52 + 55 1 0 0 @@ -858,7 +894,7 @@ 6 - 53 + 56 1 0 0 @@ -878,7 +914,7 @@ 0 7 - 54 + 57 1 0 0 @@ -890,7 +926,7 @@ 7 - 55 + 58 1 0 0 @@ -902,7 +938,7 @@ 7 - 56 + 59 1 0 0 @@ -914,7 +950,7 @@ 7 - 57 + 60 1 0 0 @@ -926,7 +962,7 @@ 7 - 58 + 61 1 0 0 @@ -938,7 +974,7 @@ 7 - 59 + 62 1 0 0 @@ -950,7 +986,7 @@ 7 - 60 + 63 1 0 0 @@ -962,7 +998,7 @@ 7 - 61 + 64 1 0 0 @@ -974,7 +1010,7 @@ 7 - 62 + 65 1 0 0 @@ -986,7 +1022,7 @@ 7 - 63 + 66 1 0 0 @@ -998,7 +1034,7 @@ 7 - 64 + 67 1 0 0 @@ -1010,7 +1046,7 @@ 7 - 65 + 68 1 0 0 @@ -1022,7 +1058,7 @@ 7 - 66 + 69 1 0 0 @@ -1034,7 +1070,7 @@ 7 - 67 + 70 1 0 0 @@ -1046,7 +1082,7 @@ 7 - 68 + 71 1 0 0 @@ -1058,7 +1094,7 @@ 7 - 69 + 72 1 0 0 @@ -1070,7 +1106,7 @@ 7 - 70 + 73 1 0 0 @@ -1080,6 +1116,30 @@ 0 0 + + 7 + 74 + 1 + 0 + 0 + 0 + ..\libraries\STM32F4xx_HAL\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_i2c.c + stm32f4xx_hal_i2c.c + 0 + 0 + + + 7 + 75 + 1 + 0 + 0 + 0 + ..\libraries\STM32F4xx_HAL\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_i2c_ex.c + stm32f4xx_hal_i2c_ex.c + 0 + 0 + diff --git a/bsp/stm32/stm32f469-st-disco/project.uvproj b/bsp/stm32/stm32f469-st-disco/project.uvproj index a2d91b54f3..8c41ab4ed7 100644 --- a/bsp/stm32/stm32f469-st-disco/project.uvproj +++ b/bsp/stm32/stm32f469-st-disco/project.uvproj @@ -359,7 +359,7 @@ USE_HAL_DRIVER, STM32F469xx - .;..\..\..\include;applications;board;board\CubeMX_Config\Inc;board\ports;..\libraries\HAL_Drivers;..\libraries\HAL_Drivers\config;..\..\..\libcpu\arm\common;..\..\..\libcpu\arm\cortex-m4;..\..\..\components\drivers\include;..\..\..\components\drivers\include;..\..\..\components\drivers\include;..\..\..\components\finsh;..\libraries\STM32F4xx_HAL\STM32F4xx_HAL_Driver\Inc;..\libraries\STM32F4xx_HAL\CMSIS\Device\ST\STM32F4xx\Include;..\libraries\STM32F4xx_HAL\CMSIS\Include + .;..\..\..\include;applications;board;board\CubeMX_Config\Inc;board\ports;..\libraries\HAL_Drivers;..\libraries\HAL_Drivers\config;..\..\..\libcpu\arm\common;..\..\..\libcpu\arm\cortex-m4;..\..\..\components\drivers\include;..\..\..\components\drivers\include;..\..\..\components\drivers\include;..\..\..\components\drivers\include;..\..\..\components\finsh;..\libraries\STM32F4xx_HAL\STM32F4xx_HAL_Driver\Inc;..\libraries\STM32F4xx_HAL\CMSIS\Device\ST\STM32F4xx\Include;..\libraries\STM32F4xx_HAL\CMSIS\Include @@ -561,6 +561,13 @@ ..\libraries\HAL_Drivers\drv_usart.c + + + drv_soft_i2c.c + 1 + ..\libraries\HAL_Drivers\drv_soft_i2c.c + + drv_common.c @@ -609,6 +616,27 @@ DeviceDrivers + + + i2c_core.c + 1 + ..\..\..\components\drivers\i2c\i2c_core.c + + + + + i2c_dev.c + 1 + ..\..\..\components\drivers\i2c\i2c_dev.c + + + + + i2c-bit-ops.c + 1 + ..\..\..\components\drivers\i2c\i2c-bit-ops.c + + pin.c @@ -909,6 +937,20 @@ ..\libraries\STM32F4xx_HAL\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_usart.c + + + stm32f4xx_hal_i2c.c + 1 + ..\libraries\STM32F4xx_HAL\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_i2c.c + + + + + stm32f4xx_hal_i2c_ex.c + 1 + ..\libraries\STM32F4xx_HAL\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_i2c_ex.c + + diff --git a/bsp/stm32/stm32f469-st-disco/project.uvprojx b/bsp/stm32/stm32f469-st-disco/project.uvprojx index e7d26b6d60..426084b731 100644 --- a/bsp/stm32/stm32f469-st-disco/project.uvprojx +++ b/bsp/stm32/stm32f469-st-disco/project.uvprojx @@ -338,7 +338,7 @@ USE_HAL_DRIVER, STM32F469xx - .;..\..\..\include;applications;board;board\CubeMX_Config\Inc;board\ports;..\libraries\HAL_Drivers;..\libraries\HAL_Drivers\config;..\..\..\libcpu\arm\common;..\..\..\libcpu\arm\cortex-m4;..\..\..\components\drivers\include;..\..\..\components\drivers\include;..\..\..\components\drivers\include;..\..\..\components\finsh;..\libraries\STM32F4xx_HAL\STM32F4xx_HAL_Driver\Inc;..\libraries\STM32F4xx_HAL\CMSIS\Device\ST\STM32F4xx\Include;..\libraries\STM32F4xx_HAL\CMSIS\Include + .;..\..\..\include;applications;board;board\CubeMX_Config\Inc;board\ports;..\libraries\HAL_Drivers;..\libraries\HAL_Drivers\config;..\..\..\libcpu\arm\common;..\..\..\libcpu\arm\cortex-m4;..\..\..\components\drivers\include;..\..\..\components\drivers\include;..\..\..\components\drivers\include;..\..\..\components\drivers\include;..\..\..\components\finsh;..\libraries\STM32F4xx_HAL\STM32F4xx_HAL_Driver\Inc;..\libraries\STM32F4xx_HAL\CMSIS\Device\ST\STM32F4xx\Include;..\libraries\STM32F4xx_HAL\CMSIS\Include @@ -542,6 +542,21 @@ DeviceDrivers + + i2c_core.c + 1 + ..\..\..\components\drivers\i2c\i2c_core.c + + + i2c_dev.c + 1 + ..\..\..\components\drivers\i2c\i2c_dev.c + + + i2c-bit-ops.c + 1 + ..\..\..\components\drivers\i2c\i2c-bit-ops.c + pin.c 1 @@ -762,6 +777,16 @@ 1 ..\libraries\STM32F4xx_HAL\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_usart.c + + stm32f4xx_hal_i2c.c + 1 + ..\libraries\STM32F4xx_HAL\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_i2c.c + + + stm32f4xx_hal_i2c_ex.c + 1 + ..\libraries\STM32F4xx_HAL\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_i2c_ex.c + diff --git a/components/dfs/Kconfig b/components/dfs/Kconfig index 35c7cf1b02..c93fd02e66 100644 --- a/components/dfs/Kconfig +++ b/components/dfs/Kconfig @@ -113,6 +113,7 @@ if RT_USING_DFS config RT_USING_DFS_RAMFS bool "Enable RAM file system" + select RT_USING_MEMHEAP default n config RT_USING_DFS_UFFS diff --git a/components/net/sal_socket/src/sal_socket.c b/components/net/sal_socket/src/sal_socket.c index 581761103a..f4d5549aad 100644 --- a/components/net/sal_socket/src/sal_socket.c +++ b/components/net/sal_socket/src/sal_socket.c @@ -139,7 +139,7 @@ static void check_netdev_internet_up_work(struct rt_work *work, void *work_data) #define SAL_INTERNET_MONTH_LEN 4 #define SAL_INTERNET_DATE_LEN 16 - int index, sockfd = 0, result = 0; + int index, sockfd = -1, result = 0; struct sockaddr_in server_addr; struct hostent *host; struct timeval timeout; diff --git a/include/rtdef.h b/include/rtdef.h index 9b12093dc7..743b91d959 100644 --- a/include/rtdef.h +++ b/include/rtdef.h @@ -656,6 +656,7 @@ struct rt_semaphore struct rt_ipc_object parent; /**< inherit from ipc_object */ rt_uint16_t value; /**< value of semaphore. */ + rt_uint16_t reserved; /**< reserved field */ }; typedef struct rt_semaphore *rt_sem_t; #endif diff --git a/src/ipc.c b/src/ipc.c index 7f603cfc4d..74faf6ac7e 100644 --- a/src/ipc.c +++ b/src/ipc.c @@ -201,6 +201,7 @@ rt_err_t rt_sem_init(rt_sem_t sem, rt_uint8_t flag) { RT_ASSERT(sem != RT_NULL); + RT_ASSERT(value < 0x10000U); /* init object */ rt_object_init(&(sem->parent.parent), RT_Object_Class_Semaphore, name); @@ -209,7 +210,7 @@ rt_err_t rt_sem_init(rt_sem_t sem, rt_ipc_object_init(&(sem->parent)); /* set init value */ - sem->value = value; + sem->value = (rt_uint16_t)value; /* set parent */ sem->parent.parent.flag = flag; @@ -261,6 +262,7 @@ rt_sem_t rt_sem_create(const char *name, rt_uint32_t value, rt_uint8_t flag) rt_sem_t sem; RT_DEBUG_NOT_IN_INTERRUPT; + RT_ASSERT(value < 0x10000U); /* allocate object */ sem = (rt_sem_t)rt_object_allocate(RT_Object_Class_Semaphore, name);