diff --git a/examples/acomp/main.c b/examples/acomp/main.c new file mode 100644 index 00000000..2f354a83 --- /dev/null +++ b/examples/acomp/main.c @@ -0,0 +1,59 @@ +/** + * @file main.c + * @brief + * + * Copyright (c) 2021 Bouffalolab team + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + */ +#include "hal_pm.h" +#include "hal_acomp.h" +#include "hal_uart.h" + +void pm_irq_callback(enum pm_event_type event) +{ + if (event == PM_HBN_ACOMP0_WAKEUP_EVENT) { + MSG("acomp0 int\r\n"); + } else if (event == PM_HBN_ACOMP1_WAKEUP_EVENT) { + MSG("acomp1 int\r\n"); + } +} + +int main(void) +{ + bflb_platform_init(0); + + pm_hbn_out1_irq_register(); + acomp_device_t acomp_device; + acomp_device.id = 1; + acomp_device.pos_ch = ACOMP_CHANNEL_ADC_CHANNEL6; //GPIO7 + acomp_device.neg_ch = ACOMP_CHANNEL_0P375VBAT; + acomp_device.pos_hysteresis_vol = ACOMP_HYSTERESIS_VOLT_50MV; + acomp_device.neg_hysteresis_vol = ACOMP_HYSTERESIS_VOLT_50MV; + acomp_init(&acomp_device); + + acomp_device.id = 0; + acomp_device.pos_ch = ACOMP_CHANNEL_ADC_CHANNEL2; //GPIO17 + acomp_device.neg_ch = ACOMP_CHANNEL_0P375VBAT; + acomp_device.pos_hysteresis_vol = ACOMP_HYSTERESIS_VOLT_50MV; + acomp_device.neg_hysteresis_vol = ACOMP_HYSTERESIS_VOLT_50MV; + acomp_init(&acomp_device); + + while (1) { + bflb_platform_delay_ms(100); + } +} diff --git a/examples/gpio/gpio_int/main.c b/examples/gpio/gpio_int/main.c index a3aaff3b..bf150a08 100644 --- a/examples/gpio/gpio_int/main.c +++ b/examples/gpio/gpio_int/main.c @@ -22,25 +22,28 @@ */ #include "hal_gpio.h" -static void gpio11_int_callback(uint32_t pin) +static void gpio_int_callback(uint32_t pin) { - MSG("gpio rising trigger !\r\n"); -} -static void gpio12_int_callback(uint32_t pin) -{ - MSG("gpio high level int !\r\n"); + MSG("gpio :%d rising trigger !\r\n", pin); } int main(void) { bflb_platform_init(0); - gpio_set_mode(GPIO_PIN_11, GPIO_SYNC_RISING_TRIGER_INT_MODE); - gpio_attach_irq(GPIO_PIN_11, gpio11_int_callback); - gpio_irq_enable(GPIO_PIN_11, ENABLE); - gpio_set_mode(GPIO_PIN_12, GPIO_SYNC_HIGH_LEVEL_INT_MODE); - gpio_attach_irq(GPIO_PIN_12, gpio12_int_callback); - gpio_irq_enable(GPIO_PIN_12, ENABLE); + gpio_set_mode(GPIO_PIN_18, GPIO_SYNC_FALLING_TRIGER_INT_MODE); + gpio_attach_irq(GPIO_PIN_18, gpio_int_callback); + gpio_irq_enable(GPIO_PIN_18, ENABLE); + gpio_set_mode(GPIO_PIN_19, GPIO_SYNC_FALLING_TRIGER_INT_MODE); + gpio_attach_irq(GPIO_PIN_19, gpio_int_callback); + gpio_irq_enable(GPIO_PIN_19, ENABLE); + gpio_set_mode(GPIO_PIN_20, GPIO_SYNC_RISING_TRIGER_INT_MODE); + gpio_attach_irq(GPIO_PIN_20, gpio_int_callback); + gpio_irq_enable(GPIO_PIN_20, ENABLE); + gpio_set_mode(GPIO_PIN_21, GPIO_SYNC_RISING_TRIGER_INT_MODE); + gpio_attach_irq(GPIO_PIN_21, gpio_int_callback); + gpio_irq_enable(GPIO_PIN_21, ENABLE); + MSG("gpio int test !\r\n"); BL_CASE_SUCCESS; diff --git a/examples/i2c/i2c_ssd1306/main.c b/examples/i2c/i2c_ssd1306/main.c new file mode 100644 index 00000000..9d712892 --- /dev/null +++ b/examples/i2c/i2c_ssd1306/main.c @@ -0,0 +1,41 @@ +/** + * @file main.c + * @brief + * + * Copyright (c) 2021 Bouffalolab team + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + */ +#include "ssd1306.h" +#include "hal_uart.h" + +int main(void) +{ + bflb_platform_init(0); + ssd1306_init(); + ssd1306_clear_screen(0x00); + ssd1306_display_off(); + + ssd1306_display_string(2, 0, "hello, bouffalo!", 16, 1); + ssd1306_display_string(2, 18, "this is an i2c driver demo!", 16, 1); + ssd1306_refresh_gram(); + ssd1306_display_on(); + + while (1) { + bflb_platform_delay_ms(100); + } +} \ No newline at end of file diff --git a/examples/i2s/i2s_play_from_flash/CMakeLists.txt b/examples/i2s/i2s_play_from_flash/CMakeLists.txt index 240ea3d5..8a8d27bd 100644 --- a/examples/i2s/i2s_play_from_flash/CMakeLists.txt +++ b/examples/i2s/i2s_play_from_flash/CMakeLists.txt @@ -1,7 +1,7 @@ set(BSP_COMMON_DIR ${CMAKE_SOURCE_DIR}/bsp/bsp_common) set(TARGET_REQUIRED_LIBS fatfs) -set(TARGET_REQUIRED_PRIVATE_INCLUDE ${BSP_COMMON_DIR}/es8388 ${BSP_COMMON_DIR}/spi_sd) -set(TARGET_REQUIRED_SRCS ${BSP_COMMON_DIR}/es8388/bsp_es8388.c ${BSP_COMMON_DIR}/fatfs/fatfs_spi_sd.c ${BSP_COMMON_DIR}/spi_sd/bsp_spi_sd.c) +set(TARGET_REQUIRED_PRIVATE_INCLUDE ${BSP_COMMON_DIR}/es8388 ${BSP_COMMON_DIR}/wm8978 ${BSP_COMMON_DIR}/spi_sd) +set(TARGET_REQUIRED_SRCS ${BSP_COMMON_DIR}/es8388/bsp_es8388.c ${BSP_COMMON_DIR}/wm8978/wm8978.c ${BSP_COMMON_DIR}/fatfs/fatfs_spi_sd.c ${BSP_COMMON_DIR}/spi_sd/bsp_spi_sd.c) set(mains main.c) generate_bin() diff --git a/examples/lvgl/CMakeLists.txt b/examples/lvgl/CMakeLists.txt index e8818fcc..2057d8b4 100644 --- a/examples/lvgl/CMakeLists.txt +++ b/examples/lvgl/CMakeLists.txt @@ -1,9 +1,9 @@ set(BSP_COMMON_DIR ${CMAKE_SOURCE_DIR}/bsp/bsp_common) set(TARGET_REQUIRED_LIBS fatfs lvgl) -set(LINKER_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/lvgl_flash.ld) -set(TARGET_REQUIRED_PRIVATE_INCLUDE ${BSP_COMMON_DIR}/il9341 ${BSP_COMMON_DIR}/lvgl ${BSP_COMMON_DIR}/touch ${BSP_COMMON_DIR}/spi_sd) +set(TARGET_REQUIRED_PRIVATE_INCLUDE ${BSP_COMMON_DIR}/mcu_lcd ${BSP_COMMON_DIR}/lvgl ${BSP_COMMON_DIR}/touch ${BSP_COMMON_DIR}/spi_sd) file(GLOB_RECURSE sources "${CMAKE_CURRENT_SOURCE_DIR}/demo/*.c") -set(TARGET_REQUIRED_SRCS ${sources} ${BSP_COMMON_DIR}/il9341/bsp_il9341.c ${BSP_COMMON_DIR}/lvgl/lv_port_disp.c ${BSP_COMMON_DIR}/lvgl/lv_port_indev.c ${BSP_COMMON_DIR}/lvgl/lv_port_fs.c +set(TARGET_REQUIRED_SRCS ${BSP_COMMON_DIR}/lvgl/lv_port_disp.c ${sources} ${BSP_COMMON_DIR}/mcu_lcd/mcu_lcd.c ${BSP_COMMON_DIR}/mcu_lcd/ili9341.c ${BSP_COMMON_DIR}/mcu_lcd/st7735s.c ${BSP_COMMON_DIR}/mcu_lcd/st7789v.c ${BSP_COMMON_DIR}/mcu_lcd/font.c + ${BSP_COMMON_DIR}/lvgl/lv_port_indev.c ${BSP_COMMON_DIR}/lvgl/lv_port_fs.c ${BSP_COMMON_DIR}/touch/xpt2046.c ${BSP_COMMON_DIR}/touch/touch.c ${BSP_COMMON_DIR}/fatfs/fatfs_spi_sd.c ${BSP_COMMON_DIR}/spi_sd/bsp_spi_sd.c) set(mains main.c) generate_bin() diff --git a/examples/lvgl/main.c b/examples/lvgl/main.c index 0a2497dd..b98834ec 100644 --- a/examples/lvgl/main.c +++ b/examples/lvgl/main.c @@ -34,7 +34,6 @@ #include "hal_gpio.h" #include "hal_dma.h" -#include "bsp_il9341.h" #include "xpt2046.h" #include "lv_port_disp.h" #include "lv_port_indev.h" diff --git a/examples/pm/hbn_mode_wakeup/CMakeLists.txt b/examples/pm/hbn_mode_wakeup/CMakeLists.txt new file mode 100644 index 00000000..27d34535 --- /dev/null +++ b/examples/pm/hbn_mode_wakeup/CMakeLists.txt @@ -0,0 +1,4 @@ +set(TARGET_REQUIRED_LIBS shell) +set(mains main.c) +generate_bin() + diff --git a/examples/pm/pds_mode_wakeup/CMakeLists.txt b/examples/pm/pds_mode_wakeup/CMakeLists.txt new file mode 100644 index 00000000..27d34535 --- /dev/null +++ b/examples/pm/pds_mode_wakeup/CMakeLists.txt @@ -0,0 +1,4 @@ +set(TARGET_REQUIRED_LIBS shell) +set(mains main.c) +generate_bin() + diff --git a/examples/pm/pds_mode_wakeup/main.c b/examples/pm/pds_mode_wakeup/main.c new file mode 100644 index 00000000..94f6de3e --- /dev/null +++ b/examples/pm/pds_mode_wakeup/main.c @@ -0,0 +1,77 @@ +/** + * @file main.c + * @brief + * + * Copyright (c) 2021 Bouffalolab team + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + */ +#include "hal_uart.h" +#include "hal_pm.h" +#include "hal_gpio.h" +#include "shell.h" + +void shell_irq_callback(struct device *dev, void *args, uint32_t size, uint32_t state) +{ + uint8_t data; + if (state == UART_EVENT_RX_FIFO) { + data = *(uint8_t *)args; + shell_handler(data); + } +} + +static void gpio_int_callback(uint32_t pin) +{ + MSG("gpio :%d rising trigger !\r\n", pin); +} + +int main(void) +{ + bflb_platform_init(0); + shell_init(); + struct device *uart = device_find("debug_log"); + if (uart) { + device_set_callback(uart, shell_irq_callback); + device_control(uart, DEVICE_CTRL_SET_INT, (void *)(UART_RX_FIFO_IT)); + } + gpio_attach_irq(GPIO_PIN_10, gpio_int_callback); + gpio_irq_enable(GPIO_PIN_10, ENABLE); //only used for level3 + while (1) { + bflb_platform_delay_ms(100); + } +} + +int pds3_enter(int argc, char *argv[]) +{ + MSG("gpio wake up case,enter pds3 mode\r\n"); + bflb_platform_delay_ms(50); + + pm_pds_mode_enter(PM_PDS_LEVEL_3, 0); /*hbn、pds、exti gpio can wakeup*/ + BL_CASE_SUCCESS; /*level 3 can run here*/ + return 0; +} +int pds31_enter(int argc, char *argv[]) +{ + MSG("gpio wake up case,enter pds31 mode\r\n"); + bflb_platform_delay_ms(50); + + pm_pds_mode_enter(PM_PDS_LEVEL_31, 0); /*hbn、pds gpio can wakeup*/ + + return 0; +} +SHELL_CMD_EXPORT(pds3_enter, pds3 gpio wakeup test) +SHELL_CMD_EXPORT(pds31_enter, pds31 gpio wakeup test) \ No newline at end of file diff --git a/examples/usb/usb2uart/dev_cfg.h b/examples/usb/usb2uart/dev_cfg.h new file mode 100644 index 00000000..c4d40268 --- /dev/null +++ b/examples/usb/usb2uart/dev_cfg.h @@ -0,0 +1,7 @@ +#ifndef DEV_CFG_H +#define DEV_CFG_H + +#define UART_DTR_PIN GPIO_PIN_22 +#define UART_RTS_PIN GPIO_PIN_21 + +#endif \ No newline at end of file diff --git a/examples/usb/usb2uart/main.c b/examples/usb/usb2uart/main.c index 7cf2e559..7274f376 100644 --- a/examples/usb/usb2uart/main.c +++ b/examples/usb/usb2uart/main.c @@ -27,6 +27,7 @@ #include "bl702_ef_ctrl.h" #include "bl702_glb.h" #include "hal_gpio.h" +#include "dev_cfg.h" #define CDC_IN_EP 0x82 #define CDC_OUT_EP 0x01 @@ -256,9 +257,6 @@ usbd_endpoint_t cdc_in_ep = { extern struct device *usb_dc_init(void); -#define UART_DTR_PIN GPIO_PIN_22 -#define UART_RTS_PIN GPIO_PIN_21 - int main(void) { uint8_t chipid[8]; diff --git a/examples/usb/usb_cdc_loopback/main.c b/examples/usb/usb_cdc_loopback/main.c index 7801bc92..eb463388 100644 --- a/examples/usb/usb_cdc_loopback/main.c +++ b/examples/usb/usb_cdc_loopback/main.c @@ -124,6 +124,8 @@ void usbd_cdc_acm_bulk_out(uint8_t ep) usbd_ep_read(ep, NULL, 0, NULL); usbd_ep_write(CDC_IN_EP, out_buffer, actual_read_length, NULL); + if (actual_read_length == 64) + usbd_ep_write(CDC_IN_EP, NULL, 0, NULL); } void usbd_cdc_acm_bulk_in(uint8_t ep)