diff --git a/docs/development_guide/build/doctrees/api_reference/board.doctree b/docs/development_guide/build/doctrees/api_reference/board.doctree deleted file mode 100644 index f2b0f7dc..00000000 Binary files a/docs/development_guide/build/doctrees/api_reference/board.doctree and /dev/null differ diff --git a/docs/development_guide/build/doctrees/api_reference/peripheral/api_dma.doctree b/docs/development_guide/build/doctrees/api_reference/peripheral/api_dma.doctree index 29b76a49..b7944308 100644 Binary files a/docs/development_guide/build/doctrees/api_reference/peripheral/api_dma.doctree and b/docs/development_guide/build/doctrees/api_reference/peripheral/api_dma.doctree differ diff --git a/docs/development_guide/build/doctrees/api_reference/peripheral/api_pwm.doctree b/docs/development_guide/build/doctrees/api_reference/peripheral/api_pwm.doctree index 5fce916f..b4b11339 100644 Binary files a/docs/development_guide/build/doctrees/api_reference/peripheral/api_pwm.doctree and b/docs/development_guide/build/doctrees/api_reference/peripheral/api_pwm.doctree differ diff --git a/docs/development_guide/build/doctrees/api_reference/peripheral/api_spi.doctree b/docs/development_guide/build/doctrees/api_reference/peripheral/api_spi.doctree index ffaf70a2..436b69c8 100644 Binary files a/docs/development_guide/build/doctrees/api_reference/peripheral/api_spi.doctree and b/docs/development_guide/build/doctrees/api_reference/peripheral/api_spi.doctree differ diff --git a/docs/development_guide/build/doctrees/api_reference/peripheral/api_timer.doctree b/docs/development_guide/build/doctrees/api_reference/peripheral/api_timer.doctree index 56883a3b..169d0ce0 100644 Binary files a/docs/development_guide/build/doctrees/api_reference/peripheral/api_timer.doctree and b/docs/development_guide/build/doctrees/api_reference/peripheral/api_timer.doctree differ diff --git a/docs/development_guide/build/doctrees/api_reference/peripheral/api_uart.doctree b/docs/development_guide/build/doctrees/api_reference/peripheral/api_uart.doctree index 5a747780..eb02f1e5 100644 Binary files a/docs/development_guide/build/doctrees/api_reference/peripheral/api_uart.doctree and b/docs/development_guide/build/doctrees/api_reference/peripheral/api_uart.doctree differ diff --git a/docs/development_guide/build/doctrees/api_reference/usb stack/api_usb_stack.doctree b/docs/development_guide/build/doctrees/api_reference/usb stack/api_usb_stack.doctree index 93fbb8b6..62cca4ba 100644 Binary files a/docs/development_guide/build/doctrees/api_reference/usb stack/api_usb_stack.doctree and b/docs/development_guide/build/doctrees/api_reference/usb stack/api_usb_stack.doctree differ diff --git a/docs/development_guide/build/doctrees/environment.pickle b/docs/development_guide/build/doctrees/environment.pickle index 5f9bad51..89e4be97 100644 Binary files a/docs/development_guide/build/doctrees/environment.pickle and b/docs/development_guide/build/doctrees/environment.pickle differ diff --git a/docs/development_guide/build/doctrees/get_started/board.doctree b/docs/development_guide/build/doctrees/get_started/board.doctree new file mode 100644 index 00000000..bdecb3d2 Binary files /dev/null and b/docs/development_guide/build/doctrees/get_started/board.doctree differ diff --git a/docs/development_guide/build/doctrees/index.doctree b/docs/development_guide/build/doctrees/index.doctree index 086c55e0..5087a84d 100644 Binary files a/docs/development_guide/build/doctrees/index.doctree and b/docs/development_guide/build/doctrees/index.doctree differ diff --git a/docs/development_guide/build/doctrees/samples/basic samples/i2s/i2s_play_from_flash_demo.doctree b/docs/development_guide/build/doctrees/samples/basic samples/i2s/i2s_play_from_flash_demo.doctree new file mode 100644 index 00000000..2edd6d1b Binary files /dev/null and b/docs/development_guide/build/doctrees/samples/basic samples/i2s/i2s_play_from_flash_demo.doctree differ diff --git a/docs/development_guide/build/doctrees/samples/basic samples/i2s/index.doctree b/docs/development_guide/build/doctrees/samples/basic samples/i2s/index.doctree new file mode 100644 index 00000000..c4f7df09 Binary files /dev/null and b/docs/development_guide/build/doctrees/samples/basic samples/i2s/index.doctree differ diff --git a/docs/development_guide/build/html/_images/config_wizard_example1.png b/docs/development_guide/build/html/_images/config_wizard_example1.png new file mode 100644 index 00000000..a2cdc1ef Binary files /dev/null and b/docs/development_guide/build/html/_images/config_wizard_example1.png differ diff --git a/docs/development_guide/build/html/_images/config_wizard_example2.png b/docs/development_guide/build/html/_images/config_wizard_example2.png new file mode 100644 index 00000000..fd1cc605 Binary files /dev/null and b/docs/development_guide/build/html/_images/config_wizard_example2.png differ diff --git a/docs/development_guide/build/html/_images/configuration_wizard_1.png b/docs/development_guide/build/html/_images/configuration_wizard_1.png new file mode 100644 index 00000000..cdf7b65d Binary files /dev/null and b/docs/development_guide/build/html/_images/configuration_wizard_1.png differ diff --git a/docs/development_guide/build/html/_images/configuration_wizard_2.png b/docs/development_guide/build/html/_images/configuration_wizard_2.png new file mode 100644 index 00000000..fc23f618 Binary files /dev/null and b/docs/development_guide/build/html/_images/configuration_wizard_2.png differ diff --git a/docs/development_guide/build/html/_sources/api_reference/peripheral/api_dma.rst.txt b/docs/development_guide/build/html/_sources/api_reference/peripheral/api_dma.rst.txt index 6fb7cac4..9785f716 100644 --- a/docs/development_guide/build/html/_sources/api_reference/peripheral/api_dma.rst.txt +++ b/docs/development_guide/build/html/_sources/api_reference/peripheral/api_dma.rst.txt @@ -316,21 +316,31 @@ DMA 设备除了标准的控制命令,还具有自己特殊的控制命令。 ``args`` 根据不同的 ``cmd`` 传入不同,具体如下: -+---------------------------+-------------+------------------------+ -|cmd |args |description | -+===========================+=============+========================+ -|DEVICE_CTRL_SET_INT |NULL |开启dma传输完成中断 | -+---------------------------+-------------+------------------------+ -|DEVICE_CTRL_CLR_INT |NULL |关闭dma传输完成中断 | -+---------------------------+-------------+------------------------+ -|DMA_CHANNEL_GET_STATUS |NULL |获取dma通道完成状态 | -+---------------------------+-------------+------------------------+ -|DMA_CHANNEL_START |NULL |开启dma通道 | -+---------------------------+-------------+------------------------+ -|DMA_CHANNEL_STOP |NULL |关闭dma通道 | -+---------------------------+-------------+------------------------+ -|DMA_CHANNEL_UPDATE |uint32_t |更新dma传输配置 | -+---------------------------+-------------+------------------------+ +.. list-table:: table1 + :widths: 15 10 30 + :header-rows: 1 + + * - cmd + - args + - description + * - DEVICE_CTRL_SET_INT + - NULL + - 开启 dma 传输完成中断 + * - DEVICE_CTRL_CLR_INT + - NULL + - 关闭 dma 传输完成中断 + * - DMA_CHANNEL_GET_STATUS + - NULL + - 获取 dma 通道完成状态 + * - DMA_CHANNEL_START + - NULL + - 开启 dma 通道 + * - DMA_CHANNEL_STOP + - NULL + - 关闭 dma 通道 + * - DMA_CHANNEL_UPDATE + - NULL + - 更新 dma 传输配置 **device_set_callback** ^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/docs/development_guide/build/html/_sources/api_reference/peripheral/api_pwm.rst.txt b/docs/development_guide/build/html/_sources/api_reference/peripheral/api_pwm.rst.txt index 11b771d3..634db9d6 100644 --- a/docs/development_guide/build/html/_sources/api_reference/peripheral/api_pwm.rst.txt +++ b/docs/development_guide/build/html/_sources/api_reference/peripheral/api_pwm.rst.txt @@ -181,23 +181,28 @@ PWM 设备除了标准的控制命令,还具有自己特殊的控制命令。 ``args`` 根据不同的 ``cmd`` 传入不同,具体如下: -+------------------------------------------+---------------------------+--------------------------+ -|cmd |args |description | -+==========================================+===========================+==========================+ -|DEVICE_CTRL_SET_INT |NULL |弃用 | -+------------------------------------------+---------------------------+--------------------------+ -|DEVICE_CTRL_CLR_INT |NULL |弃用 | -+------------------------------------------+---------------------------+--------------------------+ -|DEVICE_CTRL_RESUME |NULL |开启当前PWM通道 | -+------------------------------------------+---------------------------+--------------------------+ -|DEVICE_CTRL_SUSPEND |NULL |关闭当前PWM通道 | -+------------------------------------------+---------------------------+--------------------------+ -|DEVICE_CTRL_PWM_FREQUENCE_CONFIG |uint32_t |配置当前PWM通道周期值 | -+------------------------------------------+---------------------------+--------------------------+ -|DEVICE_CTRL_PWM_DUTYCYCLE_CONFIG |pwm_dutycycle_config_t |配置当前PWM通道占空比 | -+------------------------------------------+---------------------------+--------------------------+ -|DEVICE_CTRL_PWM_IT_PULSE_COUNT_CONFIG |uint32_t |配置触发PWM中断周期值 | -+------------------------------------------+---------------------------+--------------------------+ +.. list-table:: table1 + :widths: 15 10 30 + :header-rows: 1 + + * - cmd + - args + - description + * - DEVICE_CTRL_RESUME + - NULL + - 开启当前 PWM 通道 + * - DEVICE_CTRL_SUSPEND + - NULL + - 关闭当前 PWM 通道 + * - DEVICE_CTRL_PWM_FREQUENCE_CONFIG + - NULL + - 配置当前 PWM 通道周期值 + * - DEVICE_CTRL_PWM_DUTYCYCLE_CONFIG + - NULL + - 配置当前 PWM 通道占空比 + * - DEVICE_CTRL_PWM_IT_PULSE_COUNT_CONFIG + - NULL + - 配置触发 PWM 中断周期值 **device_set_callback** ^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/docs/development_guide/build/html/_sources/api_reference/peripheral/api_spi.rst.txt b/docs/development_guide/build/html/_sources/api_reference/peripheral/api_spi.rst.txt index 76bee5c2..8a15c124 100644 --- a/docs/development_guide/build/html/_sources/api_reference/peripheral/api_spi.rst.txt +++ b/docs/development_guide/build/html/_sources/api_reference/peripheral/api_spi.rst.txt @@ -212,31 +212,46 @@ SPI 设备除了标准的控制命令,还具有自己特殊的控制命令。 ``args`` 根据不同的 ``cmd`` 传入不同,具体如下: -+---------------------------------+-------------------+-----------------------+ -|cmd |args |description | -+=================================+===================+=======================+ -|DEVICE_CTRL_SET_INT |NULL |开启spi设备中断 | -+---------------------------------+-------------------+-----------------------+ -|DEVICE_CTRL_CLR_INT |NULL |关闭spi设备中断 | -+---------------------------------+-------------------+-----------------------+ -|DEVICE_CTRL_RESUME |NULL |恢复spi设备 | -+---------------------------------+-------------------+-----------------------+ -|DEVICE_CTRL_SUSPEND |NULL |挂起spi设备 | -+---------------------------------+-------------------+-----------------------+ -|DEVICE_CTRL_ATTACH_TX_DMA |struct device* |链接发送dma设备 | -+---------------------------------+-------------------+-----------------------+ -|DEVICE_CTRL_ATTACH_RX_DMA |struct device* |链接接收dma设备 | -+---------------------------------+-------------------+-----------------------+ -|DEVICE_CTRL_SPI_CONFIG_CLOCK |uint32_t |修改SPI设备时钟 | -+---------------------------------+-------------------+-----------------------+ -|DEVICE_CTRL_TX_DMA_SUSPEND |NULL |挂起spi tx dma模式 | -+---------------------------------+-------------------+-----------------------+ -|DEVICE_CTRL_RX_DMA_SUSPEND |NULL |挂起spi rx dma模式 | -+---------------------------------+-------------------+-----------------------+ -|DEVICE_CTRL_TX_DMA_RESUME |NULL |恢复spi tx dma模式 | -+---------------------------------+-------------------+-----------------------+ -|DEVICE_CTRL_RX_DMA_RESUME |NULL |恢复spi rx dma模式 | -+---------------------------------+-------------------+-----------------------+ +.. list-table:: table1 + :widths: 15 10 30 + :header-rows: 1 + + * - cmd + - args + - description + * - DEVICE_CTRL_SET_INT + - NULL + - 开启 spi 设备中断 + * - DEVICE_CTRL_CLR_INT + - NULL + - 关闭 spi 设备中断 + * - DEVICE_CTRL_RESUME + - NULL + - 恢复 spi 设备 + * - DEVICE_CTRL_SUSPEND + - NULL + - 挂起 spi 设备 + * - DEVICE_CTRL_ATTACH_TX_DMA + - NULL + - 链接发送 dma 设备 + * - DEVICE_CTRL_ATTACH_RX_DMA + - NULL + - 链接接收 dma 设备 + * - DEVICE_CTRL_SPI_CONFIG_CLOCK + - NULL + - 修改 spi 设备时钟 + * - DEVICE_CTRL_TX_DMA_SUSPEND + - NULL + - 挂起spi tx dma模式 + * - DEVICE_CTRL_RX_DMA_SUSPEND + - NULL + - 挂起spi rx dma模式 + * - DEVICE_CTRL_TX_DMA_RESUME + - NULL + - 恢复spi tx dma模式 + * - DEVICE_CTRL_RX_DMA_RESUME + - NULL + - 恢复spi rx dma模式 **device_write** ^^^^^^^^^^^^^^^^ diff --git a/docs/development_guide/build/html/_sources/api_reference/peripheral/api_timer.rst.txt b/docs/development_guide/build/html/_sources/api_reference/peripheral/api_timer.rst.txt index 23228745..11be3610 100644 --- a/docs/development_guide/build/html/_sources/api_reference/peripheral/api_timer.rst.txt +++ b/docs/development_guide/build/html/_sources/api_reference/peripheral/api_timer.rst.txt @@ -23,27 +23,30 @@ TIMER 设备结构体定义 typedef struct timer_device { struct device parent; uint8_t id; - uint8_t ch; - uint8_t clk_div; - timer_cnt_mode cnt_mode; - timer_pl_trig_t pl_trig_src; + enum timer_cnt_mode_type cnt_mode; + enum timer_preload_trigger_type trigger; + uint32_t reload; + uint32_t timeout1; + uint32_t timeout2; + uint32_t timeout3; } timer_device_t; - parent 继承父类属性 - id 定时器 id ,使能定时器 0 则 id 为 0 ,使能定时器 1 则 id 为 1 ,以此类推 -- ch timer 的通道号 -- clk_div 时钟分频系数 -- cnt_mode 计数模式 -- pl_trig_src 比较器的触发源 - +- cnt_mode 计数模式:FreeRun 和 PreLoad +- trigger 比较器的触发源 +- reload 重装载值,只有在 PreLoad 模式下有效 +- timeout1 COMP0 超时时间,单位 us +- timeout2 COMP1 超时时间,单位 us +- timeout3 COMP2 超时时间,单位 us ``ch`` 提供以下类型 .. code-block:: C enum timer_index_type { - TIMER_CH0_INDEX, - TIMER_CH1_INDEX, + TIMER0_INDEX, + TIMER1_INDEX, TIMER_MAX_INDEX }; @@ -51,21 +54,21 @@ TIMER 设备结构体定义 .. code-block:: C - typedef enum { + enum timer_cnt_mode_type { TIMER_CNT_PRELOAD, TIMER_CNT_FREERUN, - } timer_cnt_mode; + }; -``pl_trig_src`` 提供以下类型 +``trigger`` 提供以下类型 .. code-block:: C - typedef enum { - TIMER_PL_TRIG_NONE, - TIMER_PL_TRIG_COMP0, - TIMER_PL_TRIG_COMP1, - TIMER_PL_TRIG_COMP2, - } timer_pl_trig_t; + enum timer_preload_trigger_type { + TIMER_PRELOAD_TRIGGER_NONE, + TIMER_PRELOAD_TRIGGER_COMP0, + TIMER_PRELOAD_TRIGGER_COMP1, + TIMER_PRELOAD_TRIGGER_COMP2, + }; TIMER 设备参数配置表 ------------------------ @@ -75,39 +78,44 @@ TIMER 设备参数配置表 .. code-block:: C /*参数配置宏*/ - #if defined(BSP_USING_TIMER_CH0) - #ifndef TIMER_CH0_CONFIG - #define TIMER_CH0_CONFIG \ - { \ - .id = 0, \ - .ch = 0, \ - .cnt_mode = TIMER_CNT_PRELOAD, \ - .pl_trig_src = TIMER_PL_TRIG_COMP0, \ + #if defined(BSP_USING_TIMER0) + #ifndef TIMER0_CONFIG + #define TIMER0_CONFIG \ + { \ + .id = 0, \ + .cnt_mode = TIMER_CNT_PRELOAD, \ + .trigger = TIMER_PRELOAD_TRIGGER_COMP2, \ + .reload = 0, \ + .timeout1 = 1000000, \ + .timeout2 = 2000000, \ + .timeout3 = 3000000, \ } #endif #endif - #if defined(BSP_USING_TIMER_CH1) - #ifndef TIMER_CH1_CONFIG - #define TIMER_CH1_CONFIG \ - { \ - .id = 0, \ - .ch = 1, \ - .cnt_mode = TIMER_CNT_PRELOAD, \ - .pl_trig_src = TIMER_PL_TRIG_COMP2, \ + #if defined(BSP_USING_TIMER1) + #ifndef TIMER1_CONFIG + #define TIMER1_CONFIG \ + { \ + .id = 1, \ + .cnt_mode = TIMER_CNT_PRELOAD, \ + .trigger = TIMER_PRELOAD_TRIGGER_COMP0, \ + .reload = 0, \ + .timeout1 = 1000000, \ + .timeout2 = 2000000, \ + .timeout3 = 3000000, \ } #endif #endif /*变量定义*/ - enum timer_index_type { - #ifdef BSP_USING_TIMER_CH0 - TIMER_CH0_INDEX, + static timer_device_t timerx_device[TIMER_MAX_INDEX] = { + #ifdef BSP_USING_TIMER0 + TIMER0_CONFIG, #endif - #ifdef BSP_USING_TIMER_CH1 - TIMER_CH1_INDEX, + #ifdef BSP_USING_TIMER1 + TIMER1_CONFIG, #endif - TIMER_MAX_INDEX }; .. note:: 上述配置可以通过 ``TIMER_DEV(dev)->xxx`` 进行修改,只能在调用 ``device_open`` 之前使用。 @@ -120,7 +128,7 @@ TIMER 设备接口全部遵循标准设备驱动管理层提供的接口。 **timer_register** ^^^^^^^^^^^^^^^^^^^^^^^^ -``timer_register`` 用来注册 TIMER 设备标准驱动接口,在注册之前需要打开对应 TIMER 设备的宏定义。例如定义宏 ``BSP_USING_TIMER_CH0`` 方可使用 ``TIMER_CH0_INDEX`` 设备,注册完成以后才可以使用其他接口,如果没有定义宏,则无法使用 ``TIMER_CH0_INDEX`` 设备。 +``timer_register`` 用来注册 TIMER 设备标准驱动接口,在注册之前需要打开对应 TIMER 设备的宏定义。例如定义宏 ``BSP_USING_TIMER0`` 方可使用 ``TIMER0_INDEX`` 设备,注册完成以后才可以使用其他接口,如果没有定义宏,则无法使用 ``TIMER0_INDEX`` 设备。 .. code-block:: C @@ -129,16 +137,16 @@ TIMER 设备接口全部遵循标准设备驱动管理层提供的接口。 - index 要注册的设备索引 - name 为注册的设备命名 -``index`` 用来选择 TIMER 设备配置,一个 index 对应一个 TIMER 设备配置,比如 ``TIMER_CH0_INDEX`` 对应 ``TIMER_CH0_CONFIG`` 配置,``index`` 有如下可选类型 +``index`` 用来选择 TIMER 设备配置,一个 index 对应一个 TIMER 设备配置,比如 ``TIMER0_INDEX`` 对应 ``TIMER0_CONFIG`` 配置,``index`` 有如下可选类型 .. code-block:: C enum timer_index_type { - #ifdef BSP_USING_TIMER_CH0 - TIMER_CH0_INDEX, + #ifdef BSP_USING_TIMER0 + TIMER0_INDEX, #endif - #ifdef BSP_USING_TIMER_CH1 - TIMER_CH1_INDEX, + #ifdef BSP_USING_TIMER1 + TIMER1_INDEX, #endif TIMER_MAX_INDEX }; @@ -160,11 +168,12 @@ TIMER 设备接口全部遵循标准设备驱动管理层提供的接口。 .. code-block:: C - #define DEVICE_OFLAG_INT 0x01 - #define DEVICE_OFLAG_POLL 0x02 - #define DEVICE_CTRL_TIMER_CH_START 0x80 - #define DEVICE_CTRL_TIMER_CH_STOP 0x81 - #define DEVICE_CTRL_GET_MATCH_STATUS 0x82 + #define DEVICE_OFLAG_STREAM_TX 0x001 /* 设备以轮训发送模式打开 */ + #define DEVICE_OFLAG_STREAM_RX 0x002 /* 设备以轮训接收模式打开 */ + #define DEVICE_OFLAG_INT_TX 0x004 /* 设备以中断发送模式打开 */ + #define DEVICE_OFLAG_INT_RX 0x008 /* 设备以中断接收模式打开 */ + #define DEVICE_OFLAG_DMA_TX 0x010 /* 设备以 DMA 发送模式打开 */ + #define DEVICE_OFLAG_DMA_RX 0x020 /* 设备以 DMA 接收模式打开 */ **device_close** ^^^^^^^^^^^^^^^^ @@ -192,14 +201,6 @@ TIMER 设备接口全部遵循标准设备驱动管理层提供的接口。 - args 控制参数 - return 不同的控制命令返回的意义不同。 -TIMER 设备除了标准的控制命令,还具有私有的控制命令。 - -.. code-block:: C - - #define DEVICE_CTRL_TIMER_CH_START 0x80 - #define DEVICE_CTRL_TIMER_CH_STOP 0x81 - #define DEVICE_CTRL_GET_MATCH_STATUS 0x82 - ``args`` 根据不同的 ``cmd`` 传入不同,具体如下: .. list-table:: table1 @@ -215,25 +216,33 @@ TIMER 设备除了标准的控制命令,还具有私有的控制命令。 * - DEVICE_CTRL_CLR_INT - NULL - 关闭 TIMER 中断 + * - DEVICE_CTRL_GET_INT + - NULL + - 获取当前中断状态 * - DEVICE_CTRL_RESUME - NULL - - 开启 TIMER + - 开启 TIMER 设备 * - DEVICE_CTRL_SUSPEND - NULL - - 关闭 TIMER - * - DEVICE_CTRL_TIMER_CH_START - - timer_user_cfg_t - - 开启 TIMER 及其中断 - * - DEVICE_CTRL_TIMER_CH_STOP - - timer_user_cfg_t - - 关闭 TIMER 及其中断 + - 关闭 TIMER 设备 * - DEVICE_CTRL_GET_CONFIG - NULL - 获取 TIMER 当前的计数值 - * - DEVICE_CTRL_GET_MATCH_STATUS - - uint32_t - - 获取 TIMER 比较器的状态 +**device_write** +^^^^^^^^^^^^^^^^ + +``device_write`` 用于 Timer 设备配置超时时间。实际调用 ``timer_write``。 + +.. code-block:: C + + int device_write(struct device *dev, uint32_t pos, const void *buffer, uint32_t size); + +- dev 设备句柄 +- pos 无作用 +- buffer timer_timeout_cfg_t 句柄 +- size timer_timeout_cfg_t 个数 +- return 错误码,0 表示写入成功,其他表示错误 **device_set_callback** ^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/docs/development_guide/build/html/_sources/api_reference/peripheral/api_uart.rst.txt b/docs/development_guide/build/html/_sources/api_reference/peripheral/api_uart.rst.txt index dd49087a..75723b95 100644 --- a/docs/development_guide/build/html/_sources/api_reference/peripheral/api_uart.rst.txt +++ b/docs/development_guide/build/html/_sources/api_reference/peripheral/api_uart.rst.txt @@ -204,34 +204,46 @@ UART 设备接口全部遵循标准设备驱动管理层提供的接口。 ``args`` 根据不同的 ``cmd`` 传入不同,具体如下: +.. list-table:: table1 + :widths: 15 10 30 + :header-rows: 1 -+---------------------------------+---------------------+------------------------------+ -|cmd |args |description | -+=================================+=====================+==============================+ -|DEVICE_CTRL_SET_INT |uart_it_type |开启uart设备中断 | -+---------------------------------+---------------------+------------------------------+ -|DEVICE_CTRL_CLR_INT |uart_it_type |关闭uart设备中断 | -+---------------------------------+---------------------+------------------------------+ -|DEVICE_CTRL_CONFIG |uart_param_cfg_t* |修改串口配置 | -+---------------------------------+---------------------+------------------------------+ -|DEVICE_CTRL_ATTACH_TX_DMA |struct device* |链接发送dma设备 | -+---------------------------------+---------------------+------------------------------+ -|DEVICE_CTRL_ATTACH_RX_DMA |struct device* |链接接收dma设备 | -+---------------------------------+---------------------+------------------------------+ -|DEVICE_CTRL_ATTACH_RX_DMA |struct device* |链接接收dma设备 | -+---------------------------------+---------------------+------------------------------+ -|DEVICE_CTRL_TX_DMA_SUSPEND |NULL |挂起uart tx dma模式 | -+---------------------------------+---------------------+------------------------------+ -|DEVICE_CTRL_RX_DMA_SUSPEND |NULL |挂起uart rx dma模式 | -+---------------------------------+---------------------+------------------------------+ -|DEVICE_CTRL_TX_DMA_RESUME |NULL |恢复uart tx dma模式 | -+---------------------------------+---------------------+------------------------------+ -|DEVICE_CTRL_RX_DMA_RESUME |NULL |恢复uart rx dma模式 | -+---------------------------------+---------------------+------------------------------+ -|DEVICE_CTRL_UART_GET_TX_FIFO |uint32_t* |获取uart 发送fifo数据个数 | -+---------------------------------+---------------------+------------------------------+ -|DEVICE_CTRL_UART_GET_RX_FIFO |uint32_t* |获取uart 接收fifo数据个数 | -+---------------------------------+---------------------+------------------------------+ + * - cmd + - args + - description + * - DEVICE_CTRL_SET_INT + - uart_it_type + - 开启 uart 设备中断 + * - DEVICE_CTRL_CLR_INT + - uart_it_type + - 关闭 uart 设备中断 + * - DEVICE_CTRL_CONFIG + - uart_param_cfg_t* + - 修改串口配置 + * - DEVICE_CTRL_ATTACH_TX_DMA + - NULL + - 链接发送 dma 设备 + * - DEVICE_CTRL_ATTACH_RX_DMA + - NULL + - 链接接收 dma 设备 + * - DEVICE_CTRL_TX_DMA_SUSPEND + - NULL + - 挂起uart tx dma模式 + * - DEVICE_CTRL_RX_DMA_SUSPEND + - NULL + - 挂起uart rx dma模式 + * - DEVICE_CTRL_TX_DMA_RESUME + - NULL + - 恢复uart tx dma模式 + * - DEVICE_CTRL_RX_DMA_RESUME + - NULL + - 恢复uart rx dma模式 + * - DEVICE_CTRL_UART_GET_TX_FIFO + - uint32_t* + - 获取uart tx fifo 数据个数 + * - DEVICE_CTRL_UART_GET_RX_FIFO + - uint32_t* + - 获取uart rx fifo 数据个数 **device_write** ^^^^^^^^^^^^^^^^ diff --git a/docs/development_guide/build/html/_sources/api_reference/usb stack/api_usb_stack.rst.txt b/docs/development_guide/build/html/_sources/api_reference/usb stack/api_usb_stack.rst.txt index 8f631733..ef19e6e3 100644 --- a/docs/development_guide/build/html/_sources/api_reference/usb stack/api_usb_stack.rst.txt +++ b/docs/development_guide/build/html/_sources/api_reference/usb stack/api_usb_stack.rst.txt @@ -62,29 +62,191 @@ USB DEVICE 通用接口 **usbd_desc_register** """""""""""""""""""""""""""""""""""" +``usbd_desc_register`` 用来注册 USB 描述符,描述符种类包括:设备描述符、配置描述符、接口描述符、字符串描述符、设备限定描述符。 + +.. code-block:: C + + void usbd_desc_register(const uint8_t *desc); + +- desc 描述符的句柄 + + **usbd_msosv1_desc_register** """""""""""""""""""""""""""""""""""" +``usbd_msosv1_desc_register`` 用来注册一个 WINUSB 描述符,格式按照 ``struct usb_msosv1_descriptor``。 + +.. code-block:: C + + void usbd_msosv1_desc_register(struct usb_msosv1_descriptor *desc); + +- desc 描述符句柄 + + **usbd_class_add_interface** """""""""""""""""""""""""""""""""""" +``usbd_class_add_interface`` 用来给 USB 设备类增加接口,并将接口信息挂载在类的链表上。 + +.. code-block:: C + + void usbd_class_add_interface(usbd_class_t *class, usbd_interface_t *intf); + +- class USB 设备类的句柄 +- intf USB 设备接口的句柄 + +``usbd_class_t`` 定义如下 + +.. code-block:: C + + typedef struct usbd_class { + usb_slist_t list; + const char *name; + usb_slist_t intf_list; + } usbd_class_t; + +- list 类的链表节点 +- name 类的名称 +- intf_list 接口的链表节点 + +``usbd_interface_t`` 定义如下 + +.. code-block:: C + + typedef struct usbd_interface { + usb_slist_t list; + /** Handler for USB Class specific Control (EP 0) communications */ + usbd_request_handler class_handler; + /** Handler for USB Vendor specific commands */ + usbd_request_handler vendor_handler; + /** Handler for USB custom specific commands */ + usbd_request_handler custom_handler; + /** Handler for USB event notify commands */ + usbd_notify_handler notify_handler; + uint8_t intf_num; + usb_slist_t ep_list; + } usbd_interface_t; + +- list 接口的链表节点 +- class_handler class setup 请求回调函数 +- vendor_handler vendor setup 请求回调函数 +- custom_handler custom setup 请求回调函数 +- notify_handler 中断标志、协议栈相关状态回调函数 +- intf_num 当前接口偏移 +- ep_list 端点的链表节点 + **usbd_interface_add_endpoint** """""""""""""""""""""""""""""""""""" +``usbd_interface_add_endpoint`` 用来给 USB 接口增加端点,并将端点信息挂载在接口的链表上。 + +.. code-block:: C + + void usbd_interface_add_endpoint(usbd_interface_t *intf, usbd_endpoint_t *ep); + + +- intf USB 设备接口的句柄 +- ep USB 设备端点的句柄 + +``usbd_class_t`` 定义如下 + +.. code-block:: C + + typedef struct usbd_endpoint { + usb_slist_t list; + uint8_t ep_addr; + usbd_endpoint_callback ep_cb; + } usbd_endpoint_t; + +- list 端点的链表节点 +- ep_addr 端点地址 +- ep_cb 端点中断回调函数 + **usb_device_is_configured** """""""""""""""""""""""""""""""""""" +``usb_device_is_configured`` 用来检查 USB 设备是否被配置(枚举)。 + +.. code-block:: C + + bool usb_device_is_configured(void); + +- return 配置状态, 0 表示未配置, 1 表示配置成功 + + USB Device CDC 类接口 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +**usbd_cdc_add_acm_interface** +"""""""""""""""""""""""""""""""""""" + +``usbd_cdc_add_acm_interface`` 用来给 USB CDC ACM 类添加接口,并重写该接口相关的函数。重写的函数包括 ``cdc_acm_class_request_handler`` 和 ``cdc_notify_handler``, +其中 ``cdc_acm_class_request_handler`` 用于处理 USB CDC ACM Setup 中断请求, ``cdc_notify_handler`` 用于实现 USB CDC 其他中断回调函数。 + +.. code-block:: C + + void usbd_cdc_add_acm_interface(usbd_class_t *class, usbd_interface_t *intf); + +- class 类的句柄 +- intf 接口句柄 + USB Device MSC 类接口 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +**usbd_msc_class_init** +"""""""""""""""""""""""""""""""""""" +``usbd_msc_class_init`` 用于初始化 USB MSC 类,注册 USB CDC ACM 设备并为其添加接口,且为接口添加 BLUK OUT 、BULK IN 端点及其回调函数。 + +.. code-block:: C + + void usbd_msc_class_init(uint8_t out_ep, uint8_t in_ep); + +- out_ep 输出端点的地址 +- in_ep 输入端点的地址 + + USB Device HID 类接口 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +**usbd_hid_add_interface** +"""""""""""""""""""""""""""""""""""" +``usbd_hid_add_interface`` 用来给 USB HID 类添加接口,并重写该接口相关的函数。重写的函数包括 ``hid_class_request_handler`` 、 ``hid_custom_request_handler`` +和 ``hid_notify_handler``,其中 ``hid_class_request_handler`` 用来处理 USB HID 类的 Setup 中断请求, ``hid_custom_request_handler`` 用来处理 USB HID 获取描述符请求, +``hid_notify_handler`` 用来处理 USB HID 类的其他中断回调函数。 + +.. code-block:: C + + void usbd_hid_add_interface(usbd_class_t *class, usbd_interface_t *intf); + +- class 类的句柄 +- intf 接口句柄 + + USB Device AUDIO 类接口 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +**usbd_audio_add_interface** +"""""""""""""""""""""""""""""""""""" +``usbd_audio_add_interface`` 用来给 USB Audio 类添加接口,并重写该接口相关的函数。重写的函数包括 ``audio_class_request_handler`` 和 ``audio_notify_handler``。 + +.. code-block:: C + + void usbd_audio_add_interface(usbd_class_t *class, usbd_interface_t *intf); + +- class 类的句柄 +- intf 接口句柄 + + USB Device VIDEO 类接口 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +**usbd_video_add_interface** +"""""""""""""""""""""""""""""""""""" +``usbd_video_add_interface`` 用来给 USB Video 类添加接口,并重写该接口相关的函数。重写的函数包括 ``video_class_request_handler`` 和 ``video_notify_handler``。 + +.. code-block:: C + + void usbd_video_add_interface(usbd_class_t *class, usbd_interface_t *intf); + +- class 类的句柄 +- intf 接口句柄 \ No newline at end of file diff --git a/docs/development_guide/build/html/_sources/api_reference/board.rst.txt b/docs/development_guide/build/html/_sources/get_started/board.rst.txt similarity index 58% rename from docs/development_guide/build/html/_sources/api_reference/board.rst.txt rename to docs/development_guide/build/html/_sources/get_started/board.rst.txt index 60b09e33..a506171d 100644 --- a/docs/development_guide/build/html/_sources/api_reference/board.rst.txt +++ b/docs/development_guide/build/html/_sources/get_started/board.rst.txt @@ -1,126 +1,187 @@ -Board 配置系统 -======================= - -为了践行 **一切皆文件** 的思想,我们针对嵌入式应用不同的硬件配置需求,提出了一套 Board 配置系统。 **Board 配置系统** 主要是用于嵌入式应用中的时钟、GPIO 、外设默认配置三个基本元素进行初始化的配置系统。 - -**Board 配置系统** 包含三个配置文件,以及一个 ``bl_config_wizard`` 图形化配置软件 - -- clock_config.h 时钟配置头文件 -- peripheral_config.h 外设配置头文件 -- pinmux_config.h 引脚功能配置头文件 -- bl_config_wizard 图形化界面配置上述三类文件 - -用户只需要修改三个配置文件,系统会自动初始化。从而无需在用户程序中,调用一系列的复杂冗长的初始化函数, Boufflao Lab 为方便用户快速简便的生成项目对应的 board 文件,提供了 ``bl_config_wizard`` 配置软件,但目前正处于开发阶段。 - -.. figure:: img/config_wizard.png - :alt: - - bl_config_wizard 软件预览 - - -Board 配置系统的文件组成 --------------------------- - -Board 系统主要针对不同的板子来使用,不同的板子创建不同的 board 文件,放在 ``bsp/board`` 目录下,并且一个 board 文件,在 **引脚不冲突** 的情况下,可以共享给不同的 demo 使用,无需再创建多个工程,减少工程文件大小。 - -.. error:: 如果引脚冲突,并且非要使用一个 board 文件,请自行修改引脚 - -**board.c** -^^^^^^^^^^^^^^^^^^^^ - -``board.c`` 主要对时钟、引脚进行初始化 - -**blxxx_config.h** -^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -``blxxx_config.h`` 主要是包含一些头文件,给 HAL 层驱动使用。 - -.. hint:: 以上两个文件无需用户更改,并且相同的 MCU 可以直接复制粘贴到自己的 board 目录使用 - -**clock_config.h** -^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -``clock_config.h`` 主要配置系统和外设的时钟源以及分频系统。 - -**peripheral_config.h** -^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -``peripheral_config.h`` 主要包含外设的使能以及参数的配置。 - -.. warning:: 以 ``#define BSP_USING_XXX`` 开头的宏,用来开启外设的配置,如果没有使能宏,则无法使用该外设的所有函数 - -.. warning:: 以 ``XXX_CONFIG`` 开头的宏,用来初始化外设的配置,后面调用 ``device_open`` 来使用该配置 - - -**pinmux_config.h** -^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -``pinmux_config.h`` 主要配置外设的 GPIO 引脚功能。 - -.. warning:: 在 mcu sdk 中,所有 demo 共享这个文件,因此有些 demo 是不能使用的,需要频繁修改该文件的引脚功能配置。如果用户已经定好了引脚的分配,则不用频繁修改。 - - -与 STM32CUBEMX 配置工具的区别 ------------------------------- - -STM32CUBEMX 也是一个配置时钟、外设和 GPIO 初始化的工具,最终生成一个完整的工程,初始化都放在 ``main.c`` 的最开始 ,GPIO 和外设初始化底层会调用到 ``stm32xxx_hal_msp.c`` 中。 - -.. code-block:: C - - /* MCU Configuration--------------------------------------------------------*/ - - /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ - HAL_Init(); - - /* USER CODE BEGIN Init */ - - /* USER CODE END Init */ - - /* Configure the system clock */ - SystemClock_Config(); - - /* USER CODE BEGIN SysInit */ - - /* USER CODE END SysInit */ - - /* Initialize all configured peripherals */ - MX_GPIO_Init(); - MX_USART1_UART_Init(); - MX_QUADSPI_Init(); - -.. code-block:: C - - void HAL_UART_MspInit(UART_HandleTypeDef* huart) - { - GPIO_InitTypeDef GPIO_InitStruct = {0}; - if(huart->Instance==UART5) - { - /* USER CODE BEGIN UART5_MspInit 0 */ - - /* USER CODE END UART5_MspInit 0 */ - /* Peripheral clock enable */ - __HAL_RCC_UART5_CLK_ENABLE(); - - __HAL_RCC_GPIOB_CLK_ENABLE(); - /**UART5 GPIO Configuration - PB12 ------> UART5_RX - PB13 ------> UART5_TX - */ - GPIO_InitStruct.Pin = GPIO_PIN_12|GPIO_PIN_13; - GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.Alternate = GPIO_AF14_UART5; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /* UART5 interrupt Init */ - HAL_NVIC_SetPriority(UART5_IRQn, 0, 0); - HAL_NVIC_EnableIRQ(UART5_IRQn); - /* USER CODE BEGIN UART5_MspInit 1 */ - - /* USER CODE END UART5_MspInit 1 */ - } - - } - -.. hint:: stm32 生成的工程都是对一个工程起作用,不能够同时编译多个工程。如果使用多个工程,就要生成多个上述两个文件。在使用多个工程时,会间接增加文件大小,增加重复文件。 +Board 配置系统使用指南 +======================= + +为了践行 **一切皆文件** 的思想,我们针对嵌入式应用不同的硬件配置需求,提出了一套 Board 配置系统。 **Board 配置系统** 主要是用于嵌入式应用中的时钟、GPIO 、外设默认配置三个基本元素进行初始化的配置系统。 + +**Board 配置系统** 包含三个配置文件,以及一个 ``bl_config_wizard`` 图形化配置软件 + +- **clock_config.h** 时钟配置头文件 +- **peripheral_config.h** 外设配置头文件 +- **pinmux_config.h** 引脚功能配置头文件 +- **bl_config_wizard** 图形化界面配置上述三类文件 + +用户只需要修改三个配置文件,系统会自动初始化,从而无需在用户程序中,调用一系列的复杂冗长的初始化函数。 Boufflao Lab 为方便用户快速简便的生成项目对应的配置文件,提供了 ``bl_config_wizard`` 配置软件,目前已支持引脚配置功能,但时钟配置和外设配置功能正处于开发阶段。 + +`bl_config_wizard`_ 支持 PC 端在线配置,目前不支持移动终端在线配置。 + +.. _bl_config_wizard: https://dev.bouffalolab.com/media/config/index.html + +.. figure:: img/config_wizard.png + :alt: + + bl_config_wizard 软件预览 + + +Board 配置系统中各文件功能介绍 +-------------------------------- + +Board 系统主要针对不同的板子来使用,不同的板子创建不同的 board 文件,放在 ``bsp/board`` 目录下,并且一个 board 文件,在 **引脚不冲突** 的情况下,可以共享给不同的 demo 使用,无需再创建多个工程,减少工程文件大小。 + +.. error:: 如果引脚冲突,并且非要使用一个 board 文件,请自行修改引脚 + +**board.c** +^^^^^^^^^^^^^^^^^^^^ + +``board.c`` 主要对时钟、引脚进行初始化 + +**blxxx_config.h** +^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +``blxxx_config.h`` 主要是包含一些头文件,给 HAL 层驱动使用。 + +.. hint:: 以上两个文件无需用户更改,并且相同的 MCU 可以直接复制粘贴到自己的 board 目录使用 + +**clock_config.h** +^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +``clock_config.h`` 主要配置系统和外设的时钟源以及分频系统。 + +**peripheral_config.h** +^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +``peripheral_config.h`` 主要包含外设的使能以及参数的配置。 + +.. warning:: 以 ``#define BSP_USING_XXX`` 开头的宏,用来开启外设的配置,如果没有使能宏,则无法使用该外设的所有函数 + +.. warning:: 以 ``XXX_CONFIG`` 开头的宏,用来初始化外设的配置,后面调用 ``device_open`` 来使用该配置 + + +**pinmux_config.h** +^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +``pinmux_config.h`` 主要配置外设的 GPIO 引脚功能。 + +.. warning:: 在 mcu sdk 中,所有 demo 共享这个文件,因此有些 demo 是不能使用的,需要频繁修改该文件的引脚功能配置。如果用户已经定好了引脚的分配,则不用频繁修改。 + +Board 配置工具 **bl_config_wizard** 的使用 +------------------------------------------------------ + +生成一个新的 **pinmux_config.h** 文件 +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +1. 在窗口栏选择 ``引脚&外设配置``; +#. 选择 MCU 型号,目前支持 ``BL706引脚配置``、 ``BL704引脚配置`` 、 ``BL702引脚配置`` ; +#. 选择引脚的功能,以 ``BL706引脚配置`` 为例,点击 **PAD_GPIO_XX** 的下拉框,选择需要的功能,如图所示; + +.. figure:: img/config_wizard_example1.png + :alt: + + 选择引脚功能图 + + +4. 配置好所有引脚功能后,点击 ``导出配置文件`` ,然后可在弹框内选择路径和修改文件名,如图所示; + +.. figure:: img/config_wizard_example2.png + :alt: + + 导出配置文件图 + +修改原有的 **pinmux_config.h** 文件 +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +往往在使用中,我们不是生成一个新的 **pinmux_config.h** 文件,而是在原有的 **pinmux_config.h** 文件基础上做修改,``bl_config_wizard`` 支持这样的需求。 + +1. 在窗口栏选择 ``引脚&外设配置``; +#. 选择 MCU 型号,目前支持 ``BL706引脚配置``、 ``BL704引脚配置`` 、 ``BL702引脚配置`` ; +#. 点击 ``导入配置文件``,然后在弹框内选择 **pinmux_config.h** 文件; +#. 选择需要修改的引脚,点击其下拉框,更改引脚功能; +#. 修改完成后,点击 ``导出配置文件`` ,然后可在弹框内选择路径和修改文件名。 + + +在 CDK 工具中修改 **pinmux_config.h** 文件 +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +- **pinmux_config.h** 同时还支持在 CDK 使用图形配置向导进行相应引脚功能的调整 +- 直接将 **pinmux_config.h** 文件拖入 CDK 文本编辑界面,在文本编辑下方即可看到 ``Configuration Wizard`` 标签 + + .. figure:: img/configuration_wizard_1.png + :alt: + + 图形配置向导 + +- 点击 ``Configuration Wizard`` 标签,即可打开图形配置向导界面 +- 通过选择下拉框即可选择该引脚支持的功能 + + .. figure:: img/configuration_wizard_2.png + :alt: + + 图形配置向导设置引脚功能 + +- 图形配置向导的具体功能和代码规则,详情请参考 CDK Help 的图形配置向导章节 + + + +与 STM32CUBEMX 配置工具的区别 +------------------------------ + +STM32CUBEMX 也是一个配置时钟、外设和 GPIO 初始化的工具,最终生成一个完整的工程,初始化都放在 ``main.c`` 的最开始 ,GPIO 和外设初始化底层会调用到 ``stm32xxx_hal_msp.c`` 中。 + +.. code-block:: C + + /* MCU Configuration--------------------------------------------------------*/ + + /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ + HAL_Init(); + + /* USER CODE BEGIN Init */ + + /* USER CODE END Init */ + + /* Configure the system clock */ + SystemClock_Config(); + + /* USER CODE BEGIN SysInit */ + + /* USER CODE END SysInit */ + + /* Initialize all configured peripherals */ + MX_GPIO_Init(); + MX_USART1_UART_Init(); + MX_QUADSPI_Init(); + +.. code-block:: C + + void HAL_UART_MspInit(UART_HandleTypeDef* huart) + { + GPIO_InitTypeDef GPIO_InitStruct = {0}; + if(huart->Instance==UART5) + { + /* USER CODE BEGIN UART5_MspInit 0 */ + + /* USER CODE END UART5_MspInit 0 */ + /* Peripheral clock enable */ + __HAL_RCC_UART5_CLK_ENABLE(); + + __HAL_RCC_GPIOB_CLK_ENABLE(); + /**UART5 GPIO Configuration + PB12 ------> UART5_RX + PB13 ------> UART5_TX + */ + GPIO_InitStruct.Pin = GPIO_PIN_12|GPIO_PIN_13; + GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + GPIO_InitStruct.Alternate = GPIO_AF14_UART5; + HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /* UART5 interrupt Init */ + HAL_NVIC_SetPriority(UART5_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(UART5_IRQn); + /* USER CODE BEGIN UART5_MspInit 1 */ + + /* USER CODE END UART5_MspInit 1 */ + } + + } + +.. hint:: stm32 生成的工程都是对一个工程起作用,不能够同时编译多个工程。如果使用多个工程,就要生成多个上述两个文件。在使用多个工程时,会间接增加文件大小,增加重复文件。 diff --git a/docs/development_guide/build/html/_sources/index.rst.txt b/docs/development_guide/build/html/_sources/index.rst.txt index c7c90126..58fea9af 100644 --- a/docs/development_guide/build/html/_sources/index.rst.txt +++ b/docs/development_guide/build/html/_sources/index.rst.txt @@ -19,12 +19,12 @@ BL MCU SDK 将为您提供博流 BL70X 系列 MCU 开发的全方位支持。 :numbered: 3 get_started/get_started + get_started/connecting_hardware get_started/index - get_started/bl_dev_cube get_started/cmake_quick_start get_started/cdk_new_project_quick_start - get_started/connecting_hardware - + get_started/bl_dev_cube + get_started/board @@ -34,7 +34,6 @@ BL MCU SDK 将为您提供博流 BL70X 系列 MCU 开发的全方位支持。 :numbered: api_reference/api_overview - api_reference/board api_reference/peripheral/index api_reference/shell/api_shell api_reference/usb stack/api_usb_stack @@ -52,6 +51,7 @@ BL MCU SDK 将为您提供博流 BL70X 系列 MCU 开发的全方位支持。 samples/basic samples/dma/index samples/basic samples/spi/index samples/basic samples/i2c/index + samples/basic samples/i2s/index samples/basic samples/adc/index samples/basic samples/timer/index diff --git a/docs/development_guide/build/html/_sources/samples/basic samples/i2s/i2s_play_from_flash_demo.rst.txt b/docs/development_guide/build/html/_sources/samples/basic samples/i2s/i2s_play_from_flash_demo.rst.txt new file mode 100644 index 00000000..8366d04d --- /dev/null +++ b/docs/development_guide/build/html/_sources/samples/basic samples/i2s/i2s_play_from_flash_demo.rst.txt @@ -0,0 +1,194 @@ +I2S - flash 内置音频播放 +========================= + +本 demo 演示 I2S 播放flash内置的音频数据, 使用的音频芯片 ES8388 解码, 另外需要使用 I2C 对 ES8388 配置。 +若使用其他音频解码芯片,请自行配置,本文档仅重点讲述 I2S 的使用,对音频芯片不做过多介绍。 + +硬件连接 +----------------------------- + +本 demo 基于 BL706_AVB 开发板,需要用到 ES8388 音频子板,连接方式如下: + +.. list-table:: + :widths: 30 30 + :header-rows: 1 + + * - GPIO function + - GPIO pin + * - CLK_OUT(MCLK) + - GPIO6 + * - I2S_BCLK + - GPIO4 + * - I2S_FS + - GPIO29 + * - I2S_DO + - GPIO30 + * - I2S_DI + - GPIO3 + * - I2C_SCL + - GPIO16 + * - I2C_SDA + - GPIO11 + +本 demo 用到的内部外设资源如下: + +.. list-table:: + :widths: 10 40 + :header-rows: 1 + + * - peripheral + - role + * - I2S + - 标准音频数据接口,用于向 ES8388 音频子板传送音频数据 + * - I2C + - 一种串行通讯总线,用于配置 ES8388 的寄存器设置 + * - DMA-CH2 + - 直接存储访问技术,用于配合 I2S 高效发送音频数据,减少对 CPU 的负载 + * - CLK_OUT + - 引脚复用对外输出指定时钟信号,用作提供MCLK时钟 + +软件实现 +----------------------------- + +- 软件代码见 ``examples/i2s/i2s_play_form_flash`` + +本文档不再详细介绍 I2C 与 DMA,仅介绍 I2S 相关配置,其他外设可以查看对应的文档。 + +配置 ``I2S, I2C, CLK_OUT(MCLK)`` 相关复用引脚,见 ``bsp/board/bl706_iot/pinmux_config.h`` 中的宏定义选项: + +.. code-block:: C + :linenos: + + #define CONFIG_GPIO6_FUNC GPIO_FUN_CLK_OUT + #define CONFIG_GPIO3_FUNC GPIO_FUN_I2S + #define CONFIG_GPIO4_FUNC GPIO_FUN_I2S + #define CONFIG_GPIO29_FUNC GPIO_FUN_I2S + #define CONFIG_GPIO30_FUNC GPIO_FUN_I2S + #define CONFIG_GPIO11_FUNC GPIO_FUN_I2C + #define CONFIG_GPIO16_FUNC GPIO_FUN_I2C + +配置 ES8388 的参数,初始化 ES8388 ,其中会用到 I2C 外设,具体过程可见 ``bsp/bsp_common/es8388/es8388.c`` + +.. code-block:: C + :linenos: + + static ES8388_Cfg_Type ES8388Cfg = { + .work_mode = ES8388_CODEC_MDOE, /*!< ES8388 work mode */ + .role = ES8388_SLAVE, /*!< ES8388 role */ + .mic_input_mode = ES8388_DIFF_ENDED_MIC, /*!< ES8388 mic input mode */ + .mic_pga = ES8388_MIC_PGA_3DB, /*!< ES8388 mic PGA */ + .i2s_frame = ES8388_LEFT_JUSTIFY_FRAME, /*!< ES8388 I2S frame */ + .data_width = ES8388_DATA_LEN_16, /*!< ES8388 I2S dataWitdh */ + }; + + /* init ES8388 Codec */ + ES8388_Init(&ES8388Cfg); + ES8388_Set_Voice_Volume(60); + +I2S 的配置与使能: + +- 使能 ``BSP_USING_I2S0`` 并配置 ``I2S`` 设备配置,见 ``bsp/board/bl706_iot/peripheral_config.h`` 中: + +.. code-block:: C + :linenos: + + #define BSP_USING_I2S0 + + #if defined(BSP_USING_I2S0) + #ifndef I2S0_CONFIG + #define I2S0_CONFIG \ + { \ + .id = 0, \ + .iis_mode = I2S_MODE_MASTER, \ + .interface_mode = I2S_MODE_LEFT, \ + .sampl_freq_hz = 16 * 1000, \ + .channel_num = I2S_FS_CHANNELS_NUM_MONO, \ + .frame_size = I2S_FRAME_LEN_16, \ + .data_size = I2S_DATA_LEN_16, \ + .fifo_threshold = 4, \ + } + +- 先调用 ``i2s_register`` 函数注册 ``I2S`` 设备 +- 然后通过 ``find`` 函数找到设备对应的句柄,保存于 ``i2s`` 中 +- 最后填写配置参数后,使用 ``device_open`` 来打开 ``I2S`` 设备 +- 如果不填写配置参数,会默认使用 ``bsp/board/bl706_avb/peripheral_config.h`` 中预设的参数 + +.. code-block:: C + :linenos: + + /* register & open i2s device */ + i2s_register(I2S0_INDEX, "I2S", DEVICE_OFLAG_RDWR); + i2s = device_find("I2S"); + if (i2s) { + I2S_DEV(i2s)->iis_mode = I2S_MODE_MASTER; + I2S_DEV(i2s)->interface_mode = I2S_MODE_LEFT; + I2S_DEV(i2s)->sampl_freq_hz = 16 * 1000; + I2S_DEV(i2s)->channel_num = I2S_FS_CHANNELS_NUM_MONO; + I2S_DEV(i2s)->frame_size = I2S_FRAME_LEN_16; + I2S_DEV(i2s)->data_size = I2S_DATA_LEN_16; + I2S_DEV(i2s)->fifo_threshold = 4; + device_open(i2s, DEVICE_OFLAG_DMA_TX | DEVICE_OFLAG_DMA_RX); + } + +DMA 的配置与使能 +- 为了 I2S 更高效,减少对 CPU 的占用,需要配置 DMA 来搬运数据,具体配置可见 DMA 文档,代码如下: + +.. code-block:: C + :linenos: + + /* register & open dma device */ + dma_register(DMA0_CH2_INDEX, "dma_ch2_i2s_tx", DEVICE_OFLAG_RDWR); + dma_ch2 = device_find("dma_ch2_i2s_tx"); + if (dma_ch2) { + DMA_DEV(dma_ch2)->direction = DMA_MEMORY_TO_PERIPH; + DMA_DEV(dma_ch2)->transfer_mode = DMA_LLI_CYCLE_MODE; + DMA_DEV(dma_ch2)->src_req = DMA_REQUEST_NONE; + DMA_DEV(dma_ch2)->dst_req = DMA_REQUEST_I2S_TX; + DMA_DEV(dma_ch2)->src_width = DMA_TRANSFER_WIDTH_16BIT; + DMA_DEV(dma_ch2)->dst_width = DMA_TRANSFER_WIDTH_16BIT; + device_open(dma_ch2, 0); + + /* connect i2s device and dma device */ + device_control(i2s, DEVICE_CTRL_ATTACH_TX_DMA, (void *)dma_ch2); + } + +最后启动 I2S-DMA ,发送包含在程序里烧录到flash里的音频数据: + +.. code-block:: C + :linenos: + + /* start send */ + device_write(i2s, 0, fhm_onechannel_16k_20, sizeof(fhm_onechannel_16k_20)); + + MSG("Play Music start \r\n"); + + BL_CASE_SUCCESS; + while (1) { + bflb_platform_delay_ms(100); + } + + +编译和烧录 +----------------------------- + +- **CDK 编译** + +打开项目中提供的工程文件:i2s_play_form_flash.cdkproj + +参照 :ref:`windows_cdk_quick_start` 的步骤编译下载即可 + +- **命令行编译** + +.. code-block:: bash + :linenos: + + $ cd /bl_mcu_sdk + $ make BOARD=bl706_avb APP=i2s_play_form_flash + +- **烧录** + 详见 :ref:`bl_dev_cube` + +实验现象 +----------------------------- + +会播放一段约为 20 秒的歌曲 \ No newline at end of file diff --git a/docs/development_guide/build/html/_sources/samples/basic samples/i2s/index.rst.txt b/docs/development_guide/build/html/_sources/samples/basic samples/i2s/index.rst.txt new file mode 100644 index 00000000..d246d777 --- /dev/null +++ b/docs/development_guide/build/html/_sources/samples/basic samples/i2s/index.rst.txt @@ -0,0 +1,9 @@ +======================= +I2S 示例 +======================= + + +.. toctree:: + :maxdepth: 1 + + I2S - 播放flash内置音乐 \ No newline at end of file diff --git a/docs/development_guide/build/html/_sources/samples/basic samples/timer/timer_interrupt_demo.rst.txt b/docs/development_guide/build/html/_sources/samples/basic samples/timer/timer_interrupt_demo.rst.txt index 20a9ea98..452b61ec 100644 --- a/docs/development_guide/build/html/_sources/samples/basic samples/timer/timer_interrupt_demo.rst.txt +++ b/docs/development_guide/build/html/_sources/samples/basic samples/timer/timer_interrupt_demo.rst.txt @@ -1,114 +1,114 @@ -TIMER - 定时器中断 -==================== - -本 demo 基于 TIMER 外设周期性触发中断模式编写。 - -软件实现 ------------------------------ - -- 软件代码见 ``examples/timer/timer_int`` - -.. code-block:: C - :linenos: - - #define TIMER_CLK_SRC (0) - #define TIMER_CLK_DIV (0) - -- 配置 ``TIMER`` 设备时钟源,见 ``drivers\bl702_driver\hal_drv\default_config\timer_config.h``和``drivers\bl702_driver\hal_drv\src\hal_timer.c`` - -.. code-block:: C - :linenos: - - #define CONFIG_GPIO14_FUNC GPIO_FUN_UART0_TX - #define CONFIG_GPIO15_FUNC GPIO_FUN_UART0_RX - -- 配置 ``UART`` 设备复用引脚,见 ``bsp/board/bl706_iot/pinmux_config.h`` - -.. code-block:: C - :linenos: - - #define BSP_USING_TIMER_CH0 - - #if defined(BSP_USING_TIMER_CH0) - #ifndef TIMER_CH0_CONFIG - #define TIMER_CH0_CONFIG \ - { \ - .id = 0, \ - .ch = 0, \ - .cnt_mode = TIMER_CNT_PRELOAD, \ - .pl_trig_src = TIMER_PL_TRIG_COMP0, \ - } - #endif - #endif - -- 使能 ``BSP_USING_TIMER_CH0`` 并配置 ``TIMER`` 设备配置,见 ``bsp/board/bl706_iot/peripheral_config.h`` - -.. code-block:: C - :linenos: - - if (timer_ch0) { - device_open(timer_ch0, DEVICE_OFLAG_INT); - device_set_callback(timer_ch0, timer_ch0_irq_callback); - device_control(timer_ch0, DEVICE_CTRL_SET_INT, NULL); - device_control(timer_ch0, DEVICE_CTRL_TIMER_CH_START, (void *)(&timer_user_cfg)); - } - -- 通过 ``timer_ch0_irq_callback`` 函数,注册用户指定的 ``TIMER0`` 中断服务函数。通过 ``device_control`` 函数使能中断和配置定时周期。 - -.. code-block:: C - :linenos: - - void timer_ch0_irq_callback(struct device *dev, void *args, uint32_t size, uint32_t state) - { - MSG("timer ch0 interrupt! \n"); - - if (state == TIMER_EVENT_COMP0) { - cnt++; - MSG("timer event comp0! cnt=%d\n", cnt); - } else if (state == TIMER_EVENT_COMP1) { - MSG("timer event comp1! \n"); - } else if (state == TIMER_EVENT_COMP2) { - MSG("timer event comp2! \n"); - } - } - - -- 此函数是示例的中断服务函数,作用是判断具体是哪个 COMP 触发的中断和打印 COMP0 触发中断的次数。 - - - ``state`` 会输入 ``TIMER`` 设备的 EVENT 类型 - - ``args`` 包含了返回数据指针 - - ``size`` 包含返回数据的长度 - - ``dev`` 为中断的 ``TIMER`` 设备句柄 - - -编译和烧录 ------------------------------ - -- **CDK 编译** - - 打开项目中提供的工程文件:timer_int.cdkproj - - 参照 :ref:`windows_cdk_quick_start` 的步骤编译下载即可 - -- **命令行编译** - -.. code-block:: bash - :linenos: - - $ cd /bl_mcu_sdk - $ make BOARD=bl706_iot APP=timer_int - -- **烧录** - - 详见 :ref:`bl_dev_cube` - - -实验现象 ------------------------------ - - 每 1 秒触发 1 次 ``timer ch0`` ``COMP0`` 中断,每次触发 ``TIMER`` 中断都会打印一次 ``timer ch0 interrupt!`` ,并且 ``cnt`` 值每次都会加 1 。 - 串口打印: - - ``timer ch0 interrupt! timer event comp0! cnt=1`` - ``timer ch0 interrupt! timer event comp0! cnt=2`` - ``timer ch0 interrupt! timer event comp0! cnt=3`` +TIMER - 定时器中断 +==================== + +本 demo 基于 TIMER 外设周期性触发中断模式编写。 + +软件实现 +----------------------------- + +- 软件代码见 ``examples/timer/timer_int`` + +.. code-block:: C + :linenos: + + #define TIMER_CLK_SRC (0) + #define TIMER_CLK_DIV (0) + +- 配置 ``TIMER`` 设备时钟源,见 ``drivers\bl702_driver\hal_drv\default_config\timer_config.h``和``drivers\bl702_driver\hal_drv\src\hal_timer.c`` + +.. code-block:: C + :linenos: + + #define CONFIG_GPIO14_FUNC GPIO_FUN_UART0_TX + #define CONFIG_GPIO15_FUNC GPIO_FUN_UART0_RX + +- 配置 ``UART`` 设备复用引脚,见 ``bsp/board/bl706_iot/pinmux_config.h`` + +.. code-block:: C + :linenos: + + #define BSP_USING_TIMER_CH0 + + #if defined(BSP_USING_TIMER_CH0) + #ifndef TIMER_CH0_CONFIG + #define TIMER_CH0_CONFIG \ + { \ + .id = 0, \ + .ch = 0, \ + .cnt_mode = TIMER_CNT_PRELOAD, \ + .pl_trig_src = TIMER_PL_TRIG_COMP0, \ + } + #endif + #endif + +- 使能 ``BSP_USING_TIMER_CH0`` 并配置 ``TIMER`` 设备配置,见 ``bsp/board/bl706_iot/peripheral_config.h`` + +.. code-block:: C + :linenos: + + if (timer_ch0) { + device_open(timer_ch0, DEVICE_OFLAG_INT); + device_set_callback(timer_ch0, timer_ch0_irq_callback); + device_control(timer_ch0, DEVICE_CTRL_SET_INT, NULL); + device_control(timer_ch0, DEVICE_CTRL_TIMER_CH_START, (void *)(&timer_user_cfg)); + } + +- 通过 ``timer_ch0_irq_callback`` 函数,注册用户指定的 ``TIMER0`` 中断服务函数。通过 ``device_control`` 函数使能中断和配置定时周期。 + +.. code-block:: C + :linenos: + + void timer_ch0_irq_callback(struct device *dev, void *args, uint32_t size, uint32_t state) + { + MSG("timer ch0 interrupt! \n"); + + if (state == TIMER_EVENT_COMP0) { + cnt++; + MSG("timer event comp0! cnt=%d\n", cnt); + } else if (state == TIMER_EVENT_COMP1) { + MSG("timer event comp1! \n"); + } else if (state == TIMER_EVENT_COMP2) { + MSG("timer event comp2! \n"); + } + } + + +- 此函数是示例的中断服务函数,作用是判断具体是哪个 COMP 触发的中断和打印 COMP0 触发中断的次数。 + + - ``state`` 会输入 ``TIMER`` 设备的 EVENT 类型 + - ``args`` 包含了返回数据指针 + - ``size`` 包含返回数据的长度 + - ``dev`` 为中断的 ``TIMER`` 设备句柄 + + +编译和烧录 +----------------------------- + +- **CDK 编译** + + 打开项目中提供的工程文件:timer_int.cdkproj + + 参照 :ref:`windows_cdk_quick_start` 的步骤编译下载即可 + +- **命令行编译** + +.. code-block:: bash + :linenos: + + $ cd /bl_mcu_sdk + $ make BOARD=bl706_iot APP=timer_int + +- **烧录** + + 详见 :ref:`bl_dev_cube` + + +实验现象 +----------------------------- + + 每 1 秒触发 1 次 ``timer ch0`` ``COMP0`` 中断,每次触发 ``TIMER`` 中断都会打印一次 ``timer ch0 interrupt!`` ,并且 ``cnt`` 值每次都会加 1 。 + 串口打印: + + ``timer ch0 interrupt! timer event comp0! cnt=1`` + ``timer ch0 interrupt! timer event comp0! cnt=2`` + ``timer ch0 interrupt! timer event comp0! cnt=3`` diff --git a/docs/development_guide/build/html/api_reference/api_overview.html b/docs/development_guide/build/html/api_reference/api_overview.html index c4cc50cd..bf441d08 100644 --- a/docs/development_guide/build/html/api_reference/api_overview.html +++ b/docs/development_guide/build/html/api_reference/api_overview.html @@ -39,8 +39,8 @@ - - + + @@ -92,11 +92,12 @@

快速开发指南

API 手册

-
  • 2. Board 配置系统
  • -
  • 3. Peripheral
  • -
  • 4. Shell
  • -
  • 5. USB Stack
  • -
  • 6. BLE
  • +
  • 2. Peripheral
  • +
  • 3. Shell
  • +
  • 4. USB Stack
  • +
  • 5. BLE
  • 基础外设例程

    进阶例程

    -

    6.2.5. bt_le_adv_update_data

    +

    5.2.5. bt_le_adv_update_data

    bt_le_adv_update_data 用来更新 BLE 广播数据。

    int bt_le_adv_update_data(const struct bt_data *ad, size_t ad_len,const struct bt_data *sd, size_t sd_len);
     
    @@ -403,14 +404,14 @@
    -

    6.2.6. bt_le_adv_stop

    +

    5.2.6. bt_le_adv_stop

    bt_le_adv_stop 用来停止 BLE 广播。

    int bt_le_adv_stop(void);
     
    -

    6.2.7. bt_le_scan_start

    +

    5.2.7. bt_le_scan_start

    bt_le_scan_start 用来开启 BLE 扫描。

    int bt_le_scan_start(const struct bt_le_scan_param *param, bt_le_scan_cb_t cb);
     
    @@ -421,14 +422,14 @@
    -

    6.2.8. bt_le_scan_stop

    +

    5.2.8. bt_le_scan_stop

    bt_le_scan_stop 用来停止 BLE 扫描。

    int bt_le_scan_stop(void);
     
    -

    6.2.9. bt_le_whitelist_add

    +

    5.2.9. bt_le_whitelist_add

    bt_le_whitelist_add 用来通过地址添加设备到白名单列表中。

    int bt_le_whitelist_add(const bt_addr_le_t *addr);
     
    @@ -438,7 +439,7 @@
    -

    6.2.10. bt_le_whitelist_rem

    +

    5.2.10. bt_le_whitelist_rem

    bt_le_whitelist_rem 用来将设备从白名单列表中移除。

    int bt_le_whitelist_rem(const bt_addr_le_t *addr);
     
    @@ -448,14 +449,14 @@
    -

    6.2.11. bt_le_whitelist_clear

    +

    5.2.11. bt_le_whitelist_clear

    bt_le_whitelist_clear 用来清除白名单列表。

    int bt_le_whitelist_clear(void);
     
    -

    6.2.12. bt_le_set_chan_map

    +

    5.2.12. bt_le_set_chan_map

    bt_le_set_chan_map 用来设置(LE)通道映射。

    int bt_le_set_chan_map(u8_t chan_map[5]);
     
    @@ -465,7 +466,7 @@
    -

    6.2.13. bt_unpair

    +

    5.2.13. bt_unpair

    bt_unpair 用来清除配对信息。

    int bt_unpair(u8_t id, const bt_addr_le_t *addr);
     
    @@ -476,7 +477,7 @@
    -

    6.2.14. bt_conn_get_info

    +

    5.2.14. bt_conn_get_info

    bt_conn_get_info 用来获取当前连接设备的信息。

    int bt_conn_get_info(const struct bt_conn *conn, struct bt_conn_info *info);
     
    @@ -487,7 +488,7 @@
    -

    6.2.15. bt_conn_get_remote_dev_info

    +

    5.2.15. bt_conn_get_remote_dev_info

    bt_conn_get_remote_dev_info 用来获取已连接设备的信息。

    int bt_conn_get_remote_dev_info(struct bt_conn_info *info);
     
    @@ -497,7 +498,7 @@
    -

    6.2.16. bt_conn_le_param_update

    +

    5.2.16. bt_conn_le_param_update

    bt_conn_le_param_update 用来更新连接参数。

    int bt_conn_le_param_update(struct bt_conn *conn,const struct bt_le_conn_param *param);
     
    @@ -508,7 +509,7 @@
    -

    6.2.17. bt_conn_disconnect

    +

    5.2.17. bt_conn_disconnect

    bt_conn_disconnect 用来断开当前连接。

    int bt_conn_disconnect(struct bt_conn *conn, u8_t reason);
     
    @@ -519,7 +520,7 @@
    -

    6.2.18. bt_conn_create_le

    +

    5.2.18. bt_conn_create_le

    bt_conn_create_le 用来创建连接。

    struct bt_conn *bt_conn_create_le(const bt_addr_le_t *peer,const struct bt_le_conn_param *param);
     
    @@ -531,7 +532,7 @@
    -

    6.2.19. bt_conn_create_auto_le

    +

    5.2.19. bt_conn_create_auto_le

    bt_conn_create_auto_le 用来自动创建连接白名单列表中的设备。

    int bt_conn_create_auto_le(const struct bt_le_conn_param *param);
     
    @@ -541,14 +542,14 @@
    -

    6.2.20. bt_conn_create_auto_stop

    +

    5.2.20. bt_conn_create_auto_stop

    bt_conn_create_auto_stop 用来停止自动创建连接白名单列表中的设备。

    int bt_conn_create_auto_stop(void);
     
    -

    6.2.21. bt_le_set_auto_conn

    +

    5.2.21. bt_le_set_auto_conn

    bt_le_set_auto_conn 用来自动创建连接远端设备。

    int bt_le_set_auto_conn(const bt_addr_le_t *addr,const struct bt_le_conn_param *param);
     
    @@ -559,7 +560,7 @@
    -

    6.2.22. bt_conn_create_slave_le

    +

    5.2.22. bt_conn_create_slave_le

    bt_conn_create_slave_le 用来发起定向的广播包给远端设备。

    struct bt_conn *bt_conn_create_slave_le(const bt_addr_le_t *peer,const struct bt_le_adv_param *param);
     
    @@ -571,7 +572,7 @@
    -

    6.2.23. bt_conn_set_security

    +

    5.2.23. bt_conn_set_security

    bt_conn_set_security 用来设置连接安全等级。

    int bt_conn_set_security(struct bt_conn *conn, bt_security_t sec);
     
    @@ -582,7 +583,7 @@
    -

    6.2.24. bt_conn_get_security

    +

    5.2.24. bt_conn_get_security

    bt_conn_get_security 用来获取当前连接的安全等级。

    bt_security_t bt_conn_get_security(struct bt_conn *conn);
     
    @@ -592,7 +593,7 @@
    -

    6.2.25. bt_conn_enc_key_size

    +

    5.2.25. bt_conn_enc_key_size

    bt_conn_enc_key_size 用来获取当前连接的加密key的大小。

    u8_t bt_conn_enc_key_size(struct bt_conn *conn);
     
    @@ -603,7 +604,7 @@
    -

    6.2.26. bt_conn_cb_register

    +

    5.2.26. bt_conn_cb_register

    bt_conn_cb_register 用来注册连接回调函数。

    void bt_conn_cb_register(struct bt_conn_cb *cb);
     
    @@ -613,7 +614,7 @@
    -

    6.2.27. bt_set_bondable

    +

    5.2.27. bt_set_bondable

    bt_set_bondable 用来设置/清除SMP配对请求/响应数据认证需求中的绑定标志。

    void bt_set_bondable(bool enable);
     
    @@ -623,7 +624,7 @@
    -

    6.2.28. bt_conn_auth_cb_register

    +

    5.2.28. bt_conn_auth_cb_register

    bt_conn_auth_cb_register 用来注册认证回调函数。

    int bt_conn_auth_cb_register(const struct bt_conn_auth_cb *cb);
     
    @@ -633,7 +634,7 @@
    -

    6.2.29. bt_conn_auth_passkey_entry

    +

    5.2.29. bt_conn_auth_passkey_entry

    bt_conn_auth_passkey_entry 用密钥回复对方。

    int bt_conn_auth_passkey_entry(struct bt_conn *conn, unsigned int passkey);
     
    @@ -644,7 +645,7 @@
    -

    6.2.30. bt_conn_auth_cancel

    +

    5.2.30. bt_conn_auth_cancel

    bt_conn_auth_cancel 用来取消认证过程。

    int bt_conn_auth_cancel(struct bt_conn *conn);
     
    @@ -654,7 +655,7 @@
    -

    6.2.31. bt_conn_auth_passkey_confirm

    +

    5.2.31. bt_conn_auth_passkey_confirm

    bt_conn_auth_passkey_confirm 用来当密码匹配时,回复对方。

    int bt_conn_auth_passkey_confirm(struct bt_conn *conn);
     
    @@ -664,7 +665,7 @@
    -

    6.2.32. bt_conn_auth_pincode_entry

    +

    5.2.32. bt_conn_auth_pincode_entry

    bt_conn_auth_pincode_entry 用 PIN 码进行回复对方。

    int bt_conn_auth_pincode_entry(struct bt_conn *conn, const char *pin);
     
    @@ -675,7 +676,7 @@
    -

    6.2.33. bt_le_read_rssi

    +

    5.2.33. bt_le_read_rssi

    bt_le_read_rssi 用来读取对方 RSSI 值。

    int bt_le_read_rssi(u16_t handle,int8_t *rssi);
     
    @@ -686,7 +687,7 @@
    -

    6.2.34. bt_get_local_address

    +

    5.2.34. bt_get_local_address

    bt_get_local_address 用来读取本机的地址。

    int bt_get_local_address(bt_addr_le_t *adv_addr);
     
    @@ -696,7 +697,7 @@
    -

    6.2.35. bt_set_tx_pwr

    +

    5.2.35. bt_set_tx_pwr

    bt_set_tx_pwr 用来设置本机发射功率。

    int bt_set_tx_pwr(int8_t power);
     
    @@ -707,7 +708,7 @@
    -

    6.3. 数据结构参考

    +

    5.3. 数据结构参考

    bt_le_adv_param 数据结构:

    /** LE Advertising Parameters. */
     struct bt_le_adv_param {
    @@ -960,7 +961,7 @@ timeout:连接超时时间。

    -

    3.9.3. ADC 设备参数配置表

    +

    2.9.3. ADC 设备参数配置表

    每一个 ADC 设备都有一个参数配置宏,宏定义位于 bsp/board/xxx 目录下 peripheral_config.h 文件,变量定义位于 hal_adc.c 中,因此无需用户自己定义变量。当用户打开对应设备的宏,该设备的配置才生效。例如打开宏 BSP_USING_ADC0 即生效,同时 ADC 设备就可以进行注册和使用了。

    /*参数配置宏*/
     #if defined(BSP_USING_ADC0)
    @@ -301,10 +302,10 @@
     
    -

    3.9.4. ADC 设备接口

    +

    2.9.4. ADC 设备接口

    ADC 设备接口全部遵循标准设备驱动管理层提供的接口。

    -

    3.9.4.1. adc_register

    +

    2.9.4.1. adc_register

    adc_register 用来注册 ADC 设备标准驱动接口,在注册之前需要打开对应 ADC 设备的宏定义。例如定义宏 BSP_USING_ADC0 方可使用 ADC0 设备,注册完成以后才可以使用其他接口,如果没有定义宏,则无法使用 ADC0 设备。

    int adc_register(enum ADC_index_type index, const char *name);
     
    @@ -325,7 +326,7 @@
    -

    3.9.4.2. device_open

    +

    2.9.4.2. device_open

    device_open 用于 ADC 设备的打开,oflag 表示以何种方式打开。实际调用 adc_open

    int device_open(struct device *dev, uint16_t oflag);
     
    @@ -346,7 +347,7 @@
    -

    3.9.4.3. device_close

    +

    2.9.4.3. device_close

    device_close 用于设备的关闭。实际调用 adc_close

    int device_close(struct device *dev);
     
    @@ -357,7 +358,7 @@
    -

    3.9.4.4. device_control

    +

    2.9.4.4. device_control

    device_control 用于根据命令对 ADC 设备进行控制和参数的修改。实际调用 adc_control

    int device_control(struct device *dev, int cmd, void *args);
     
    @@ -440,7 +441,7 @@
    -

    3.9.4.5. device_read

    +

    2.9.4.5. device_read

    device_read 用于 ADC 设备数据的接收,接收方式根据打开方式可以是轮询、中断、dma。实际调用 adc_read

    int device_read(struct device *dev, uint32_t pos, void *buffer, uint32_t size);
     
    @@ -454,7 +455,7 @@
    -

    3.9.4.6. device_set_callback

    +

    2.9.4.6. device_set_callback

    device_set_callback 用于注册一个ADC阈值中断回调函数。

    int device_set_callback(struct device *dev, void (*callback)(struct device *dev, void *args, uint32_t size, uint32_t event));
     
    @@ -491,8 +492,8 @@
    -

    3.5.4.7. dma_channel_stop

    +

    2.5.4.7. dma_channel_stop

    dma_channel_stop 用于关闭DMA通道。实际是调用 device_control ,其中 cmdDMA_CHANNEL_STOP

    dma_channel_stop(dev)
     
    @@ -603,7 +605,7 @@
    -

    3.5.4.8. dma_channel_update

    +

    2.5.4.8. dma_channel_update

    dma_channel_update 用于更新DMA配置。实际是调用 device_control ,其中 cmdDMA_CHANNEL_UPDATE

    dma_channel_update(dev,list)
     
    @@ -614,7 +616,7 @@
    -

    3.5.4.9. dma_channel_check_busy

    +

    2.5.4.9. dma_channel_check_busy

    dma_channel_check_busy 用于查询当前使用的DMA通道是否传输完成。实际是调用 device_control ,其中 cmdDMA_CHANNEL_GET_STATUS

    dma_channel_check_busy(dev)
     
    @@ -625,7 +627,7 @@
    -

    3.5.4.10. dma_reload

    +

    2.5.4.10. dma_reload

    dma_reload 用于更新DMA某个通道的配置,相比于 dma_channel_update ,该函数无需用户传递很多参数,只需要填入源地址和目标地址,以及长度,内部会自己计算后再进行配置。此函数调用后,DMA通道是没有开启的,需要手动调用 dma_channel_start 函数。

    int dma_reload(struct device *dev, uint32_t src_addr, uint32_t dst_addr, uint32_t transfer_size);
     
    @@ -646,8 +648,8 @@
    -

    3.2.2.3. gpio_toggle

    +

    2.2.2.3. gpio_toggle

    gpio_toggle 翻转引脚电平

    void gpio_toggle(uint32_t pin);
     
    @@ -293,7 +294,7 @@
    -

    3.2.2.4. gpio_read

    +

    2.2.2.4. gpio_read

    gpio_read 读取引脚电平

    int  gpio_read(uint32_t pin);
     
    @@ -304,7 +305,7 @@
    -

    3.2.2.5. gpio_attach_irq

    +

    2.2.2.5. gpio_attach_irq

    gpio_attach_irq 为中断引脚附加中断回调函数

    void gpio_attach_irq(uint32_t pin, void (*cbfun)(uint32_t pin));
     
    @@ -315,7 +316,7 @@
    -

    3.2.2.6. gpio_irq_enable

    +

    2.2.2.6. gpio_irq_enable

    gpio_irq_enable 开启gpio某个引脚的中断

    void gpio_irq_enable(uint32_t pin,uint8_t enabled);
     
    @@ -334,8 +335,8 @@
    -

    3.6.2. I2C 设备结构体定义

    +

    2.6.2. I2C 设备结构体定义

    typedef struct i2c_device
     {
         struct device parent;
    @@ -255,7 +256,7 @@
     
     
    -

    3.6.3. I2C 设备参数配置表

    +

    2.6.3. I2C 设备参数配置表

    每一个 I2C 设备都有一个参数配置宏,宏定义位于 bsp/board/xxx 目录下 peripheral_config.h 文件,变量定义位于 hal_i2c.c 中,因此无需用户自己定义变量。当用户打开对应设备的宏,该设备的配置才生效。例如打开宏 BSP_USING_I2C0I2C0_CONFIG 即生效,同时 I2C 设备就可以进行注册和使用了。

    /*参数配置宏*/
     #if defined(BSP_USING_I2C0)
    @@ -284,10 +285,10 @@
     
    -

    3.6.4. I2C 设备接口

    +

    2.6.4. I2C 设备接口

    I2C 设备标准接口当前仅使用 device_open , 并提供标准的数据收发接口。

    -

    3.6.4.1. i2c_register

    +

    2.6.4.1. i2c_register

    i2c_register 用来注册 I2C 设备标准驱动接口,在注册之前需要打开对应 I2C 设备的宏定义。例如定义宏 BSP_USING_I2C0 方可使用 I2C0 设备,注册完成以后才可以使用其他接口,如果没有定义宏,则无法使用 I2C0 设备。

    int i2c_register(enum i2c_index_type index, const char *name);
     
    @@ -308,7 +309,7 @@
    -

    3.6.4.2. device_open

    +

    2.6.4.2. device_open

    device_open 用于设备的打开,oflag 表示以何种方式打开。实际调用 i2c_open

    int device_open(struct device *dev, uint16_t oflag);
     
    @@ -329,7 +330,7 @@
    -

    3.6.4.3. i2c_transfer

    +

    2.6.4.3. i2c_transfer

    i2c_transfer 用于设备的数据传输,形参中 msgs 中的成员 flags 指示传输的方向是写还是读,并且指定寄存器地址长度是 0、1、2。

    int i2c_transfer(struct device *dev, i2c_msg_t msgs[], uint32_t num);
     
    @@ -379,8 +380,8 @@
    -

    3.7.4.4. device_control

    +

    2.7.4.4. device_control

    device_control 用于根据命令对设备进行控制和参数的修改。实际调用 i2s_control

    int device_control(struct device *dev, int cmd, void *args);
     
    @@ -453,7 +454,7 @@
    -

    3.7.4.5. device_write

    +

    2.7.4.5. device_write

    device_write 用于 I2S 设备数据的发送,考虑到效率,目前仅支持 DMA 模式发送。

    int device_write(struct device *dev, uint32_t pos, const void *buffer, uint32_t size);
     
    @@ -467,7 +468,7 @@
    -

    3.7.4.6. device_read

    +

    2.7.4.6. device_read

    device_read 用于 I2S 设备数据的接收,考虑到效率,目前仅支持 DMA 模式接收。

    int device_read(struct device *dev, uint32_t pos, void *buffer, uint32_t size);
     
    @@ -489,8 +490,8 @@
    -

    3.4.4.4. device_control

    +

    2.4.4.4. device_control

    device_control 用于根据命令对设备进行控制和参数的修改。实际调用 pwm_control

    int device_control(struct device *dev, int cmd, void *args);
     
    @@ -400,11 +401,12 @@

    args 根据不同的 cmd 传入不同,具体如下:

    - +
    +--++ @@ -413,39 +415,31 @@ - - - - - - - - - + - + - - + + - - + + - - + +
    table1

    cmd

    DEVICE_CTRL_SET_INT

    NULL

    弃用

    DEVICE_CTRL_CLR_INT

    NULL

    弃用

    DEVICE_CTRL_RESUME

    NULL

    开启当前PWM通道

    开启当前 PWM 通道

    DEVICE_CTRL_SUSPEND

    NULL

    关闭当前PWM通道

    关闭当前 PWM 通道

    DEVICE_CTRL_PWM_FREQUENCE_CONFIG

    uint32_t

    配置当前PWM通道周期值

    NULL

    配置当前 PWM 通道周期值

    DEVICE_CTRL_PWM_DUTYCYCLE_CONFIG

    pwm_dutycycle_config_t

    配置当前PWM通道占空比

    NULL

    配置当前 PWM 通道占空比

    DEVICE_CTRL_PWM_IT_PULSE_COUNT_CONFIG

    uint32_t

    配置触发PWM中断周期值

    NULL

    配置触发 PWM 中断周期值

    -

    3.4.4.5. device_set_callback

    +

    2.4.4.5. device_set_callback

    device_set_callback 用于注册一个PWM通道中断回调函数。

    int device_set_callback(struct device *dev, void (*callback)(struct device *dev, void *args, uint32_t size, uint32_t event));
     
    @@ -472,7 +466,7 @@
    -

    3.4.4.6. pwm_channel_start

    +

    2.4.4.6. pwm_channel_start

    pwm_channel_start 用于开启PWM通道。实际是调用 device_control ,其中 cmdDEVICE_CTRL_RESUME

    pwm_channel_start(dev)
     
    @@ -482,7 +476,7 @@
    -

    3.4.4.7. pwm_channel_stop

    +

    2.4.4.7. pwm_channel_stop

    pwm_channel_stop 用于关闭PWM通道。实际是调用 device_control ,其中 cmdDEVICE_CTRL_SUSPEND

    pwm_channel_stop(dev)
     
    @@ -492,7 +486,7 @@
    -

    3.4.4.8. pwm_channel_freq_update

    +

    2.4.4.8. pwm_channel_freq_update

    pwm_channel_freq_update 用于更新PWM通道的频率。实际是调用 device_control ,其中 cmdDEIVCE_CTRL_PWM_FREQUENCE_CONFIG

    pwm_channel_freq_update(dev,count)
     
    @@ -503,7 +497,7 @@
    -

    3.4.4.9. pwm_channel_dutycycle_update

    +

    2.4.4.9. pwm_channel_dutycycle_update

    pwm_channel_dutycycle_update 用于更新PWM通道的频率。实际是调用 device_control ,其中 cmdDEIVCE_CTRL_PWM_DUTYCYCLE_CONFIG

    pwm_channel_dutycycle_update(dev,cfg)
     
    @@ -514,7 +508,7 @@
    -

    3.4.4.10. pwm_it_pulse_count_update

    +

    2.4.4.10. pwm_it_pulse_count_update

    pwm_it_pulse_count_update 用于更新PWM通道的计数值,需要先使能PWM中断才起作用,当pwm计数达到设置的周期计数值则会产生中断。实际是调用 device_control ,其中 cmdDEIVCE_CTRL_PWM_IT_PULSE_COUNT_CONFIG

    pwm_it_pulse_count_update(dev,count)
     
    @@ -533,8 +527,8 @@
    -

    3.8.2. SPI 设备结构体定义

    +

    2.8.2. SPI 设备结构体定义

    typedef struct spi_device
     {
         struct device parent;
    @@ -309,7 +310,7 @@ SDI(数据输入)、SDO(数据输出)、SCLK(时钟)、CS(片选
     
    -

    3.8.3. SPI 设备参数配置表

    +

    2.8.3. SPI 设备参数配置表

    每一个 SPI 设备都有一个参数配置宏,宏定义位于 bsp/board/xxx 目录下 peripheral_config.h 文件,变量定义位于 hal_spi.c 中,因此无需用户自己定义变量。当用户打开对应设备的宏,该设备的配置才生效。例如打开宏 BSP_USING_SPI0SPI0_CONFIG 即生效,同时 SPI0 设备就可以进行注册和使用了。

    /*参数配置宏*/
     #if defined(BSP_USING_SPI0)
    @@ -343,10 +344,10 @@ SDI(数据输入)、SDO(数据输出)、SCLK(时钟)、CS(片选
     
    -

    3.8.4. SPI 设备接口

    +

    2.8.4. SPI 设备接口

    SPI 设备接口全部遵循标准设备驱动管理层提供的接口。

    -

    3.8.4.1. spi_register

    +

    2.8.4.1. spi_register

    spi_register 用来注册 SPI 设备标准驱动接口,在注册之前需要打开对应 SPI 设备的宏定义,例如定义宏 BSP_USING_SPI0 方可使用 SPI0 设备。注册完成以后才可以使用其他接口,如果没有定义宏,则无法使用 SPI 设备。

    int spi_register(enum spi_index_type index, const char *name);
     
    @@ -367,7 +368,7 @@ SDI(数据输入)、SDO(数据输出)、SCLK(时钟)、CS(片选
    -

    3.8.4.2. device_open

    +

    2.8.4.2. device_open

    device_open 用于设备的打开,oflag 表示以何种方式打开。实际调用 spi_open

    int device_open(struct device *dev, uint16_t oflag);
     
    @@ -388,7 +389,7 @@ SDI(数据输入)、SDO(数据输出)、SCLK(时钟)、CS(片选
    -

    3.8.4.3. device_close

    +

    2.8.4.3. device_close

    device_close 用于设备的关闭。实际调用 spi_close

    int device_close(struct device *dev);
     
    @@ -399,7 +400,7 @@ SDI(数据输入)、SDO(数据输出)、SCLK(时钟)、CS(片选
    -

    3.8.4.4. device_control

    +

    2.8.4.4. device_control

    device_control 用于根据命令对设备进行控制和参数的修改。实际调用 spi_control

    int device_control(struct device *dev, int cmd, void *args);
     
    @@ -415,11 +416,12 @@ SDI(数据输入)、SDO(数据输出)、SCLK(时钟)、CS(片选

    args 根据不同的 cmd 传入不同,具体如下:

    - +
    +---+++ @@ -430,31 +432,31 @@ SDI(数据输入)、SDO(数据输出)、SCLK(时钟)、CS(片选 - + - + - + - + - - + + - - + + - - + + @@ -476,7 +478,7 @@ SDI(数据输入)、SDO(数据输出)、SCLK(时钟)、CS(片选
    table1

    cmd

    DEVICE_CTRL_SET_INT

    NULL

    开启spi设备中断

    开启 spi 设备中断

    DEVICE_CTRL_CLR_INT

    NULL

    关闭spi设备中断

    关闭 spi 设备中断

    DEVICE_CTRL_RESUME

    NULL

    恢复spi设备

    恢复 spi 设备

    DEVICE_CTRL_SUSPEND

    NULL

    挂起spi设备

    挂起 spi 设备

    DEVICE_CTRL_ATTACH_TX_DMA

    struct device*

    链接发送dma设备

    NULL

    链接发送 dma 设备

    DEVICE_CTRL_ATTACH_RX_DMA

    struct device*

    链接接收dma设备

    NULL

    链接接收 dma 设备

    DEVICE_CTRL_SPI_CONFIG_CLOCK

    uint32_t

    修改SPI设备时钟

    NULL

    修改 spi 设备时钟

    DEVICE_CTRL_TX_DMA_SUSPEND

    NULL

    -

    3.8.4.5. device_write

    +

    2.8.4.5. device_write

    device_write 用于 SPI 设备数据的发送,发送方式根据打开方式可以是轮询、中断、dma。实际调用 spi_write

    int device_write(struct device *dev, uint32_t pos, const void *buffer, uint32_t size);
     
    @@ -490,7 +492,7 @@ SDI(数据输入)、SDO(数据输出)、SCLK(时钟)、CS(片选
    -

    3.8.4.6. device_read

    +

    2.8.4.6. device_read

    device_read 用于 SPI 设备数据的接收,接收方式根据打开方式可以是轮询、中断、dma。实际调用 spi_read

    int device_read(struct device *dev, uint32_t pos, void *buffer, uint32_t size);
     
    @@ -504,7 +506,7 @@ SDI(数据输入)、SDO(数据输出)、SCLK(时钟)、CS(片选
    -

    3.8.4.7. device_set_callback

    +

    2.8.4.7. device_set_callback

    device_set_callback 用于注册一个 SPI 设备中断回调函数。

    int device_set_callback(struct device *dev, void (*callback)(struct device *dev, void *args, uint32_t size, uint32_t event));
     
    @@ -533,7 +535,7 @@ SDI(数据输入)、SDO(数据输出)、SCLK(时钟)、CS(片选
    -

    3.8.4.8. spi_transmit

    +

    2.8.4.8. spi_transmit

    spi_transmit 用于 SPI 设备数据的发送。

    int spi_transmit(struct device *dev, void *buffer, uint32_t size, uint8_t type);
     
    @@ -553,7 +555,7 @@ SDI(数据输入)、SDO(数据输出)、SCLK(时钟)、CS(片选
    -

    3.8.4.9. spi_receive

    +

    2.8.4.9. spi_receive

    spi_receive 用于 SPI 设备数据的接收。

    int spi_receive(struct device *dev, void *buffer, uint32_t size, uint8_t type);
     
    @@ -566,7 +568,7 @@ SDI(数据输入)、SDO(数据输出)、SCLK(时钟)、CS(片选
    -

    3.8.4.10. spi_transmit_receive

    +

    2.8.4.10. spi_transmit_receive

    spi_transmit_receive 用于 SPI 设备数据的发送和接收。

    int spi_transmit_receive(struct device *dev, const void *send_buf, void *recv_buf, uint32_t length, uint8_t type);
     
    @@ -588,8 +590,8 @@ SDI(数据输入)、SDO(数据输出)、SCLK(时钟)、CS(片选

    diff --git a/docs/development_guide/build/html/api_reference/peripheral/api_timer.html b/docs/development_guide/build/html/api_reference/peripheral/api_timer.html index 3fcf9baf..7aae8b7d 100644 --- a/docs/development_guide/build/html/api_reference/peripheral/api_timer.html +++ b/docs/development_guide/build/html/api_reference/peripheral/api_timer.html @@ -7,7 +7,7 @@ - 3.11. TIMER 设备 — BL_MCU_SDK 开发指南 0.3 文档 + 2.11. TIMER 设备 — BL_MCU_SDK 开发指南 0.3 文档 @@ -39,8 +39,8 @@ - - + + @@ -92,47 +92,48 @@

    快速开发指南

    API 手册

    • 1. API 概述
    • -
    • 2. Board 配置系统
    • -
    • 3. Peripheral
        -
      • 3.1. 时钟树
      • -
      • 3.2. GPIO 设备
      • -
      • 3.3. UART 设备
      • -
      • 3.4. PWM 设备
      • -
      • 3.5. DMA 设备
      • -
      • 3.6. I2C 设备
      • -
      • 3.7. I2S 设备
      • -
      • 3.8. SPI 设备
      • -
      • 3.9. ADC 设备
      • -
      • 3.10. DAC 设备
      • -
      • 3.11. TIMER 设备
          -
        • 3.11.1. 简介
        • -
        • 3.11.2. TIMER 设备结构体定义
        • -
        • 3.11.3. TIMER 设备参数配置表
        • -
        • 3.11.4. TIMER 设备接口

          基础外设例程

          进阶例程

            @@ -202,9 +204,9 @@
          • »
          • -
          • 3. Peripheral »
          • +
          • 2. Peripheral »
          • -
          • 3.11. TIMER 设备
          • +
          • 2.11. TIMER 设备
          • @@ -224,9 +226,9 @@
            -

            3.11. TIMER 设备

            +

            2.11. TIMER 设备

            -

            3.11.1. 简介

            +

            2.11.1. 简介

            TIMER 通用定时器,博流系列 MCU 中 TIMER 设备具有以下特性:

            • 多种时钟来源选择

            • @@ -240,87 +242,96 @@
            -

            3.11.2. TIMER 设备结构体定义

            +

            2.11.2. TIMER 设备结构体定义

            typedef struct timer_device {
                 struct device parent;
                 uint8_t id;
            -    uint8_t ch;
            -    uint8_t clk_div;
            -    timer_cnt_mode cnt_mode;
            -    timer_pl_trig_t pl_trig_src;
            +    enum timer_cnt_mode_type cnt_mode;
            +    enum timer_preload_trigger_type trigger;
            +    uint32_t reload;
            +    uint32_t timeout1;
            +    uint32_t timeout2;
            +    uint32_t timeout3;
             } timer_device_t;
             
            • parent 继承父类属性

            • id 定时器 id ,使能定时器 0 则 id 为 0 ,使能定时器 1 则 id 为 1 ,以此类推

            • -
            • ch timer 的通道号

            • -
            • clk_div 时钟分频系数

            • -
            • cnt_mode 计数模式

            • -
            • pl_trig_src 比较器的触发源

            • +
            • cnt_mode 计数模式:FreeRun 和 PreLoad

            • +
            • trigger 比较器的触发源

            • +
            • reload 重装载值,只有在 PreLoad 模式下有效

            • +
            • timeout1 COMP0 超时时间,单位 us

            • +
            • timeout2 COMP1 超时时间,单位 us

            • +
            • timeout3 COMP2 超时时间,单位 us

            ch 提供以下类型

            enum timer_index_type {
            -    TIMER_CH0_INDEX,
            -    TIMER_CH1_INDEX,
            +    TIMER0_INDEX,
            +    TIMER1_INDEX,
                 TIMER_MAX_INDEX
             };
             

            cnt_mode 提供以下类型

            -
            typedef enum {
            +
            enum timer_cnt_mode_type {
                 TIMER_CNT_PRELOAD,
                 TIMER_CNT_FREERUN,
            -} timer_cnt_mode;
            +};
             
            -

            pl_trig_src 提供以下类型

            -
            typedef enum {
            -    TIMER_PL_TRIG_NONE,
            -    TIMER_PL_TRIG_COMP0,
            -    TIMER_PL_TRIG_COMP1,
            -    TIMER_PL_TRIG_COMP2,
            -} timer_pl_trig_t;
            +

            trigger 提供以下类型

            +
            enum timer_preload_trigger_type {
            +    TIMER_PRELOAD_TRIGGER_NONE,
            +    TIMER_PRELOAD_TRIGGER_COMP0,
            +    TIMER_PRELOAD_TRIGGER_COMP1,
            +    TIMER_PRELOAD_TRIGGER_COMP2,
            +};
             
            -

            3.11.3. TIMER 设备参数配置表

            +

            2.11.3. TIMER 设备参数配置表

            每一个 TIMER 设备都有一个参数配置宏,宏定义位于 bsp/board/xxx 目录下 peripheral_config.h 文件,变量定义位于 hal_timer.c 中,因此无需用户自己定义变量。当用户打开对应设备的宏,该设备的配置才生效。例如打开宏 BSP_USING_TIMER_CH0TIMER_CH0_CONFIG 即生效,同时 TIMER_CH0_INDEX 设备就可以进行注册和使用了。

            /*参数配置宏*/
            -#if defined(BSP_USING_TIMER_CH0)
            -#ifndef TIMER_CH0_CONFIG
            -#define TIMER_CH0_CONFIG                    \
            -    {                                       \
            -        .id = 0,                            \
            -        .ch = 0,                            \
            -        .cnt_mode = TIMER_CNT_PRELOAD,      \
            -        .pl_trig_src = TIMER_PL_TRIG_COMP0, \
            +#if defined(BSP_USING_TIMER0)
            +#ifndef TIMER0_CONFIG
            +#define TIMER0_CONFIG                           \
            +    {                                           \
            +        .id = 0,                                \
            +        .cnt_mode = TIMER_CNT_PRELOAD,          \
            +        .trigger = TIMER_PRELOAD_TRIGGER_COMP2, \
            +        .reload = 0,                            \
            +        .timeout1 = 1000000,                    \
            +        .timeout2 = 2000000,                    \
            +        .timeout3 = 3000000,                    \
                 }
             #endif
             #endif
             
            -#if defined(BSP_USING_TIMER_CH1)
            -#ifndef TIMER_CH1_CONFIG
            -#define TIMER_CH1_CONFIG                    \
            -    {                                       \
            -        .id = 0,                            \
            -        .ch = 1,                            \
            -        .cnt_mode = TIMER_CNT_PRELOAD,      \
            -        .pl_trig_src = TIMER_PL_TRIG_COMP2, \
            +#if defined(BSP_USING_TIMER1)
            +#ifndef TIMER1_CONFIG
            +#define TIMER1_CONFIG                           \
            +    {                                           \
            +        .id = 1,                                \
            +        .cnt_mode = TIMER_CNT_PRELOAD,          \
            +        .trigger = TIMER_PRELOAD_TRIGGER_COMP0, \
            +        .reload = 0,                            \
            +        .timeout1 = 1000000,                    \
            +        .timeout2 = 2000000,                    \
            +        .timeout3 = 3000000,                    \
                 }
             #endif
             #endif
             
             /*变量定义*/
            -enum timer_index_type {
            -#ifdef BSP_USING_TIMER_CH0
            -    TIMER_CH0_INDEX,
            +static timer_device_t timerx_device[TIMER_MAX_INDEX] = {
            +#ifdef BSP_USING_TIMER0
            +    TIMER0_CONFIG,
             #endif
            -#ifdef BSP_USING_TIMER_CH1
            -    TIMER_CH1_INDEX,
            +#ifdef BSP_USING_TIMER1
            +    TIMER1_CONFIG,
             #endif
            -    TIMER_MAX_INDEX
             };
             
            @@ -330,11 +341,11 @@
            -

            3.11.4. TIMER 设备接口

            +

            2.11.4. TIMER 设备接口

            TIMER 设备接口全部遵循标准设备驱动管理层提供的接口。

            -

            3.11.4.1. timer_register

            -

            timer_register 用来注册 TIMER 设备标准驱动接口,在注册之前需要打开对应 TIMER 设备的宏定义。例如定义宏 BSP_USING_TIMER_CH0 方可使用 TIMER_CH0_INDEX 设备,注册完成以后才可以使用其他接口,如果没有定义宏,则无法使用 TIMER_CH0_INDEX 设备。

            +

            2.11.4.1. timer_register

            +

            timer_register 用来注册 TIMER 设备标准驱动接口,在注册之前需要打开对应 TIMER 设备的宏定义。例如定义宏 BSP_USING_TIMER0 方可使用 TIMER0_INDEX 设备,注册完成以后才可以使用其他接口,如果没有定义宏,则无法使用 TIMER0_INDEX 设备。

            int timer_register(enum timer_index_type index, const char *name);
             
            @@ -342,13 +353,13 @@
          • index 要注册的设备索引

          • name 为注册的设备命名

          -

          index 用来选择 TIMER 设备配置,一个 index 对应一个 TIMER 设备配置,比如 TIMER_CH0_INDEX 对应 TIMER_CH0_CONFIG 配置,index 有如下可选类型

          +

          index 用来选择 TIMER 设备配置,一个 index 对应一个 TIMER 设备配置,比如 TIMER0_INDEX 对应 TIMER0_CONFIG 配置,index 有如下可选类型

          enum timer_index_type {
          -#ifdef BSP_USING_TIMER_CH0
          -    TIMER_CH0_INDEX,
          +#ifdef BSP_USING_TIMER0
          +    TIMER0_INDEX,
           #endif
          -#ifdef BSP_USING_TIMER_CH1
          -    TIMER_CH1_INDEX,
          +#ifdef BSP_USING_TIMER1
          +    TIMER1_INDEX,
           #endif
               TIMER_MAX_INDEX
           };
          @@ -356,7 +367,7 @@
           
          -

          3.11.4.2. device_open

          +

          2.11.4.2. device_open

          device_open 用于 TIMER 设备的打开,oflag 表示以何种方式打开。实际调用 timer_open

          int device_open(struct device *dev, uint16_t oflag);
           
          @@ -367,16 +378,17 @@
        • return 错误码,0 表示打开成功,其他表示错误

        oflag 可以写入以下参数:

        -
        #define DEVICE_OFLAG_INT             0x01
        -#define DEVICE_OFLAG_POLL            0x02
        -#define DEVICE_CTRL_TIMER_CH_START   0x80
        -#define DEVICE_CTRL_TIMER_CH_STOP    0x81
        -#define DEVICE_CTRL_GET_MATCH_STATUS 0x82
        +
        #define DEVICE_OFLAG_STREAM_TX  0x001 /* 设备以轮训发送模式打开 */
        +#define DEVICE_OFLAG_STREAM_RX  0x002 /* 设备以轮训接收模式打开 */
        +#define DEVICE_OFLAG_INT_TX     0x004 /* 设备以中断发送模式打开 */
        +#define DEVICE_OFLAG_INT_RX     0x008 /* 设备以中断接收模式打开 */
        +#define DEVICE_OFLAG_DMA_TX     0x010 /* 设备以 DMA 发送模式打开 */
        +#define DEVICE_OFLAG_DMA_RX     0x020 /* 设备以 DMA 接收模式打开 */
         
        -

        3.11.4.3. device_close

        +

        2.11.4.3. device_close

        device_close 用于设备的关闭。实际调用 timer_close

        int device_close(struct device *dev);
         
        @@ -387,7 +399,7 @@
    -

    3.11.4.4. device_control

    +

    2.11.4.4. device_control

    device_control 用于根据命令对 TIMER 设备进行控制和参数的修改。实际调用 timer_control

    int device_control(struct device *dev, int cmd, void *args);
     
    @@ -398,12 +410,6 @@
  • args 控制参数

  • return 不同的控制命令返回的意义不同。

  • -

    TIMER 设备除了标准的控制命令,还具有私有的控制命令。

    -
    #define DEVICE_CTRL_TIMER_CH_START   0x80
    -#define DEVICE_CTRL_TIMER_CH_STOP    0x81
    -#define DEVICE_CTRL_GET_MATCH_STATUS 0x82
    -
    -

    args 根据不同的 cmd 传入不同,具体如下:

    @@ -427,35 +433,41 @@ - + - + - + - + - - - + + + - - - - - + - - - -
    table1

    NULL

    关闭 TIMER 中断

    DEVICE_CTRL_RESUME

    DEVICE_CTRL_GET_INT

    NULL

    开启 TIMER

    获取当前中断状态

    DEVICE_CTRL_SUSPEND

    DEVICE_CTRL_RESUME

    NULL

    关闭 TIMER

    开启 TIMER 设备

    DEVICE_CTRL_TIMER_CH_START

    timer_user_cfg_t

    开启 TIMER 及其中断

    DEVICE_CTRL_SUSPEND

    NULL

    关闭 TIMER 设备

    DEVICE_CTRL_TIMER_CH_STOP

    timer_user_cfg_t

    关闭 TIMER 及其中断

    DEVICE_CTRL_GET_CONFIG

    DEVICE_CTRL_GET_CONFIG

    NULL

    获取 TIMER 当前的计数值

    DEVICE_CTRL_GET_MATCH_STATUS

    uint32_t

    获取 TIMER 比较器的状态

    +
    +

    2.11.4.5. device_write

    +

    device_write 用于 Timer 设备配置超时时间。实际调用 timer_write

    +
    int device_write(struct device *dev, uint32_t pos, const void *buffer, uint32_t size);
    +
    +
    +
      +
    • dev 设备句柄

    • +
    • pos 无作用

    • +
    • buffer timer_timeout_cfg_t 句柄

    • +
    • size timer_timeout_cfg_t 个数

    • +
    • return 错误码,0 表示写入成功,其他表示错误

    • +
    +
    -

    3.11.4.5. device_set_callback

    +

    2.11.4.6. device_set_callback

    device_set_callback 用于注册一个 TIMER 中断回调函数。

    int device_set_callback(struct device *dev, void (*callback)(struct device *dev, void *args, uint32_t size, uint32_t event));
     
    @@ -492,8 +504,8 @@
    -

    3.3.4.4. device_control

    +

    2.3.4.4. device_control

    device_control 用于根据命令对 UART 设备进行控制和参数的修改。实际调用 uart_control

    int device_control(struct device *dev, int cmd, void *args);
     
    @@ -410,11 +411,12 @@

    args 根据不同的 cmd 传入不同,具体如下:

    - +
    +---+++ @@ -425,57 +427,53 @@ - + - + - - + + - - + + - - - - - + - + - + - + - + - + - + - +
    table1

    cmd

    DEVICE_CTRL_SET_INT

    uart_it_type

    开启uart设备中断

    开启 uart 设备中断

    DEVICE_CTRL_CLR_INT

    uart_it_type

    关闭uart设备中断

    关闭 uart 设备中断

    DEVICE_CTRL_CONFIG

    uart_param_cfg_t*

    修改串口配置

    DEVICE_CTRL_ATTACH_TX_DMA

    struct device*

    链接发送dma设备

    NULL

    链接发送 dma 设备

    DEVICE_CTRL_ATTACH_RX_DMA

    struct device*

    链接接收dma设备

    NULL

    链接接收 dma 设备

    DEVICE_CTRL_ATTACH_RX_DMA

    struct device*

    链接接收dma设备

    DEVICE_CTRL_TX_DMA_SUSPEND

    DEVICE_CTRL_TX_DMA_SUSPEND

    NULL

    挂起uart tx dma模式

    DEVICE_CTRL_RX_DMA_SUSPEND

    DEVICE_CTRL_RX_DMA_SUSPEND

    NULL

    挂起uart rx dma模式

    DEVICE_CTRL_TX_DMA_RESUME

    DEVICE_CTRL_TX_DMA_RESUME

    NULL

    恢复uart tx dma模式

    DEVICE_CTRL_RX_DMA_RESUME

    DEVICE_CTRL_RX_DMA_RESUME

    NULL

    恢复uart rx dma模式

    DEVICE_CTRL_UART_GET_TX_FIFO

    DEVICE_CTRL_UART_GET_TX_FIFO

    uint32_t*

    获取uart 发送fifo数据个数

    获取uart tx fifo 数据个数

    DEVICE_CTRL_UART_GET_RX_FIFO

    DEVICE_CTRL_UART_GET_RX_FIFO

    uint32_t*

    获取uart 接收fifo数据个数

    获取uart rx fifo 数据个数

    -

    3.3.4.5. device_write

    +

    2.3.4.5. device_write

    device_write 用于 UART 设备数据的发送,发送方式根据打开方式可以是轮询、中断、dma。实际调用 uart_write

    int device_write(struct device *dev, uint32_t pos, const void *buffer, uint32_t size);
     
    @@ -489,7 +487,7 @@
    -

    3.3.4.6. device_read

    +

    2.3.4.6. device_read

    device_read 用于 UART 设备数据的接收,接收方式根据打开方式可以是轮询、中断、dma。实际调用 uart_read

    int device_read(struct device *dev, uint32_t pos, void *buffer, uint32_t size);
     
    @@ -503,7 +501,7 @@
    -

    3.3.4.7. device_set_callback

    +

    2.3.4.7. device_set_callback

    device_set_callback 用于注册一个串口中断回调函数。

    int device_set_callback(struct device *dev, void (*callback)(struct device *dev, void *args, uint32_t size, uint32_t event));
     
    @@ -543,8 +541,8 @@
    -

    3.12.3.2. device_open

    +

    2.12.3.2. device_open

    device_open 用于设备的打开,oflag 表示以何种方式打开。实际调用 usb_open

    int device_open(struct device *dev, uint16_t oflag);
     
    @@ -329,7 +330,7 @@
    -

    3.12.3.3. device_close

    +

    2.12.3.3. device_close

    device_close 用于设备的关闭。实际调用 usb_close

    int device_close(struct device *dev);
     
    @@ -340,7 +341,7 @@
    -

    3.12.3.4. device_control

    +

    2.12.3.4. device_control

    device_control 用于根据命令对设备进行控制和参数的修改。实际调用 usb_control

    int device_control(struct device *dev, int cmd, void *args);
     
    @@ -427,7 +428,7 @@
    -

    3.12.3.5. device_write

    +

    2.12.3.5. device_write

    device_write 用于 USB 设备数据的发送,当前只支持同步传输 dma 发送,实际调用 usb_write

    int device_write(struct device *dev, uint32_t pos, const void *buffer, uint32_t size);
     
    @@ -441,7 +442,7 @@
    -

    3.12.3.6. device_read

    +

    2.12.3.6. device_read

    device_read 用于 USB 设备数据的接收,当前只支持同步传输 dma 接收。实际调用 usb_read

    int device_read(struct device *dev, uint32_t pos, void *buffer, uint32_t size);
     
    @@ -455,7 +456,7 @@
    -

    3.12.3.7. device_set_callback

    +

    2.12.3.7. device_set_callback

    device_set_callback 用于注册一个 USB 设备中断回调函数。

    int device_set_callback(struct device *dev, void (*callback)(struct device *dev, void *args, uint32_t size, uint32_t event));
     
    @@ -510,7 +511,7 @@
    -

    3.12.3.8. usb_dc_send_from_ringbuffer

    +

    2.12.3.8. usb_dc_send_from_ringbuffer

    usb_dc_send_from_ringbuffer 用于从 ringbuffer 中读取数据并通过某个端点将数据发送出去。

    int usb_dc_send_from_ringbuffer(struct device *dev, Ring_Buffer_Type *rb, uint8_t ep);
     
    @@ -523,7 +524,7 @@
    -

    3.12.3.9. usb_dc_receive_to_ringbuffer

    +

    2.12.3.9. usb_dc_receive_to_ringbuffer

    usb_dc_receive_to_ringbuffer 用于从某个端点接收数据并保存到 ringbuffer 中。

    int usb_dc_receive_to_ringbuffer(struct device *dev, Ring_Buffer_Type *rb, uint8_t ep);
     
    @@ -540,7 +541,7 @@
    -

    3.12.3.10. usb_dc_set_address

    +

    2.12.3.10. usb_dc_set_address

    usb_dc_set_address 用于 USB 设备地址的配置。

    int usb_dc_set_address(const uint8_t addr);
     
    @@ -551,7 +552,7 @@
    -

    3.12.3.11. usb_dc_ep_open

    +

    2.12.3.11. usb_dc_ep_open

    usb_dc_ep_open 用于 USB 设备端点的开启。

    int usb_dc_ep_open(const struct usbd_endpoint_cfg *ep_cfg);
     
    @@ -562,7 +563,7 @@
    -

    3.12.3.12. usb_dc_ep_close

    +

    2.12.3.12. usb_dc_ep_close

    usb_dc_ep_close 用于 USB 设备端点的关闭。

    int usb_dc_ep_close(const uint8_t ep);
     
    @@ -573,7 +574,7 @@
    -

    3.12.3.13. usb_dc_ep_set_stall

    +

    2.12.3.13. usb_dc_ep_set_stall

    usb_dc_ep_set_stall 用于 USB 设备挂起状态的设置,挂起状态下无法收发数据。

    int usb_dc_ep_set_stall(const uint8_t ep);
     
    @@ -584,7 +585,7 @@
    -

    3.12.3.14. usb_dc_ep_clear_stall

    +

    2.12.3.14. usb_dc_ep_clear_stall

    usb_dc_ep_clear_stall 用于端点挂起状态的清除,非挂起状态可以进行收发数据。

    int usb_dc_ep_clear_stall(const uint8_t ep);
     
    @@ -595,7 +596,7 @@
    -

    3.12.3.15. usb_dc_ep_is_stalled

    +

    2.12.3.15. usb_dc_ep_is_stalled

    usb_dc_ep_is_stalled 用于 USB 设备挂起状态的查询。

    int usb_dc_ep_is_stalled(const uint8_t ep, uint8_t *stalled);
     
    @@ -607,7 +608,7 @@
    -

    3.12.3.16. usb_dc_ep_write

    +

    2.12.3.16. usb_dc_ep_write

    usb_dc_ep_write 用于向某个端点发送数据。

    int usb_dc_ep_write(const uint8_t ep, const uint8_t *data, uint32_t data_len, uint32_t *ret_bytes);
     
    @@ -621,7 +622,7 @@
    -

    3.12.3.17. usb_dc_ep_read

    +

    2.12.3.17. usb_dc_ep_read

    usb_dc_ep_read 用于从某个端点接收数据。

    int usb_dc_ep_read(const uint8_t ep, uint8_t *data, uint32_t max_data_len, uint32_t *read_bytes);
     
    @@ -643,8 +644,8 @@
    -

    4.1.3. SHELL_CMD_EXPORT

    +

    3.1.3. SHELL_CMD_EXPORT

    SHELL_CMD_EXPORT 用来注册一个命令。

    @@ -249,7 +250,7 @@
    -

    4.1.4. SHELL_CMD_EXPORT_ALIAS

    +

    3.1.4. SHELL_CMD_EXPORT_ALIAS

    SHELL_CMD_EXPORT_ALIAS 用来注册一个命令,并对命令取别名。

    @@ -264,7 +265,7 @@
    -

    4.2. Shell 内置命令

    +

    3.2. Shell 内置命令

    小技巧

    help 用来显示所有注册过的命令列表

    @@ -278,8 +279,8 @@