!122 适配OpenHarmony4.1

Merge pull request !122 from goodix_zhaoxingyu/GR551x_SDK_v202
This commit is contained in:
openharmony_ci
2024-06-21 07:04:51 +00:00
committed by Gitee
671 changed files with 216 additions and 84454 deletions
Regular → Executable
View File
Regular → Executable
View File
View File
View File
Regular → Executable
View File
Regular → Executable
View File
View File
View File
View File
View File
View File
View File
@@ -1,177 +0,0 @@
/**
****************************************************************************************
*
* @file app_dma.h
* @author BLE Driver Team
* @brief Header file containing functions prototypes of DMA app library.
*
****************************************************************************************
* @attention
#####Copyright (c) 2019 GOODIX
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of GOODIX nor the names of its contributors may be used
to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
****************************************************************************************
*/
/** @addtogroup PERIPHERAL Peripheral Driver
* @{
*/
/** @addtogroup APP_DRIVER APP DRIVER
* @{
*/
/** @defgroup APP_DMA DMA
* @brief DMA APP module driver.
* @{
*/
#ifndef _APP_DMA_H_
#define _APP_DMA_H_
#include "gr55xx_hal.h"
#include "app_drv_error.h"
#ifdef __cplusplus
extern "C" {
#endif
#ifdef HAL_DMA_MODULE_ENABLED
/** @addtogroup APP_DMA_ENUMERATIONS Enumerations
* @{
*/
/**
* @brief DMA event Enumerations definition
*/
typedef enum {
APP_DMA_EVT_ERROR, /**< The event of error interrupt. */
APP_DMA_EVT_TFR, /**< The event of transfer complete interrupt. */
} app_dma_evt_type_t;
/** @} */
/** @addtogroup APP_DMA_STRUCTURES Structures
* @{
*/
/**
* @brief DMA parameters structure definition
*/
typedef struct {
dma_channel_t channel_number; /**< Specifies the channel of DMA. */
dma_init_t init; /**< DMA communication parameters. */
} app_dma_params_t;
/** @} */
/** @addtogroup APP_DMA_TYPEDEFS Typedefs
* @{
*/
/**
* @brief DMA event callback definition
*/
typedef void (*app_dma_evt_handler_t)(app_dma_evt_type_t type);
/** @} */
/* Exported functions --------------------------------------------------------*/
/** @addtogroup APP_DMA_DRIVER_FUNCTIONS Functions
* @{
*/
/**
****************************************************************************************
* @brief Initialize the APP DMA DRIVER according to the specified parameters
* in the app_dma_params_t and app_dma_evt_handler_t.
*
* @param[in] p_params: Pointer to app_dma_params_t parameter which contains the
* configuration information for the specified DMA module.
* @param[in] evt_handler: DMA user callback function.
*
* @return DMA ID
****************************************************************************************
*/
int16_t app_dma_init(app_dma_params_t *p_params, app_dma_evt_handler_t evt_handler);
/**
****************************************************************************************
* @brief De-initialize the APP ADC DRIVER peripheral.
*
* @param[in] ins_id: Deinitialize DMA channel for a specific ID.
*
* @return Result of De-initialization.
****************************************************************************************
*/
uint16_t app_dma_deinit(int16_t ins_id);
/**
****************************************************************************************
* @brief Start the DMA Transfer.
*
* @param[in] id: DMA channel id.
* @param[in] src_address: The source memory Buffer address
* @param[in] dst_address: The destination memory Buffer address
* @param[in] data_length: The length of data to be transferred from source to destination, ranging between 0 and 4095.
****************************************************************************************
*/
uint16_t app_dma_start(int16_t id, uint32_t src_address, uint32_t dst_address, uint32_t data_length);
/**
****************************************************************************************
* @brief Return the DMA handle.
*
* @param[in] id: DMA Channel ID.
*
* @return Pointer to the specified ID's DMA handle.
****************************************************************************************
*/
dma_handle_t *app_dma_get_handle(int16_t id);
#ifdef APP_DRIVER_WAKEUP_CALL_FUN
/**
****************************************************************************************
* @brief resume dma after wake up for other modules.
*
* @param[in] id: DMA Channel ID.
*
* @return void.
****************************************************************************************
*/
void dma_wake_up(int16_t id);
#endif
/** @} */
#endif
#ifdef __cplusplus
}
#endif
#endif
/** @} */
/** @} */
/** @} */
@@ -1,151 +0,0 @@
/**
****************************************************************************************
*
* @file app_drv_config.h
* @author BLE Driver Team
* @brief Header file of app driver config code.
*
****************************************************************************************
* @attention
#####Copyright (c) 2019 GOODIX
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of GOODIX nor the names of its contributors may be used
to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
****************************************************************************************
*/
/** @addtogroup PERIPHERAL Peripheral Driver
* @{
*/
/** @addtogroup APP_DRIVER APP DRIVER
* @{
*/
/** @defgroup APP_DRIVER_CONFIG DRIVER CONFIG
* @brief APP DRIVER CONFIG
* @{
*/
#ifndef _APP_DRV_CONFIG_H_
#define _APP_DRV_CONFIG_H_
#ifdef __cplusplus
extern "C" {
#endif
/**
* @defgroup APP_DRV_PERIPHERAL_PRIORITY_DEFINE Defines
* @{
*/
/**@brief APP driver peripheral priority define. */
#ifndef APP_DRIVER_ADC_WAPEUP_PRIORITY
#define APP_DRIVER_ADC_WAPEUP_PRIORITY WAPEUP_PRIORITY_HIGH /**< ADC Wakeup priority High */
#endif
#ifndef APP_DRIVER_AES_WAPEUP_PRIORITY
#define APP_DRIVER_AES_WAPEUP_PRIORITY WAPEUP_PRIORITY_MID /**< AES Wakeup priority Mid */
#endif
#ifndef APP_DRIVER_COMP_WAPEUP_PRIORITY
#define APP_DRIVER_COMP_WAPEUP_PRIORITY WAPEUP_PRIORITY_LOW /**< COMP Wakeup priority Low */
#endif
#ifndef APP_DRIVER_DUAL_TIM_WAPEUP_PRIORITY
#define APP_DRIVER_DUAL_TIM_WAPEUP_PRIORITY WAPEUP_PRIORITY_MID /**< DUAL TIM Wakeup priority Mid */
#endif
#ifndef APP_DRIVER_DMA_WAPEUP_PRIORITY
#define APP_DRIVER_DMA_WAPEUP_PRIORITY WAPEUP_PRIORITY_HIGH /**< DMA Wakeup priority High */
#endif
#ifndef APP_DRIVER_GPIOTE_WAPEUP_PRIORITY
#define APP_DRIVER_GPIOTE_WAPEUP_PRIORITY WAPEUP_PRIORITY_LOW /**< GPIOTE Wakeup priority Low */
#endif
#ifndef APP_DRIVER_SYSTICK_WAPEUP_PRIORITY
#define APP_DRIVER_SYSTICK_WAPEUP_PRIORITY WAPEUP_PRIORITY_HIGH /**< SysTick Wakeup priority High */
#endif
#ifndef APP_DRIVER_UART_WAPEUP_PRIORITY
#define APP_DRIVER_UART_WAPEUP_PRIORITY WAPEUP_PRIORITY_HIGH /**< Uart Wakeup priority High */
#endif
#ifndef APP_DRIVER_HMAC_WAPEUP_PRIORITY
#define APP_DRIVER_HMAC_WAPEUP_PRIORITY WAPEUP_PRIORITY_MID /**< Hmac Wakeup priority Mid */
#endif
#ifndef APP_DRIVER_I2C_WAPEUP_PRIORITY
#define APP_DRIVER_I2C_WAPEUP_PRIORITY WAPEUP_PRIORITY_HIGH /**< I2C Wakeup priority High */
#endif
#ifndef APP_DRIVER_I2S_WAPEUP_PRIORITY
#define APP_DRIVER_I2S_WAPEUP_PRIORITY WAPEUP_PRIORITY_HIGH /**< I2S Wakeup priority High */
#endif
#ifndef APP_DRIVER_QSPI_WAPEUP_PRIORITY
#define APP_DRIVER_QSPI_WAPEUP_PRIORITY WAPEUP_PRIORITY_HIGH /**< QSPI Wakeup priority High */
#endif
#ifndef APP_DRIVER_RNG_WAPEUP_PRIORITY
#define APP_DRIVER_RNG_WAPEUP_PRIORITY WAPEUP_PRIORITY_MID /**< RNG Wakeup priority Mid */
#endif
#ifndef APP_DRIVER_SPI_WAPEUP_PRIORITY
#define APP_DRIVER_SPI_WAPEUP_PRIORITY WAPEUP_PRIORITY_HIGH /**< SPI Wakeup priority High */
#endif
#ifndef APP_DRIVER_TIM_WAPEUP_PRIORITY
#define APP_DRIVER_TIM_WAPEUP_PRIORITY WAPEUP_PRIORITY_MID /**< TIM Wakeup priority Mid */
#endif
#ifndef APP_DRIVER_PWM_WAPEUP_PRIORITY
#define APP_DRIVER_PWM_WAPEUP_PRIORITY WAPEUP_PRIORITY_MID /**< PWM Wakeup priority Mid */
#endif
/**@} */
/**@addtogroup APP_DRV_WAPEUP_PRIORITY_ENUM Enumerations
* @{
*/
/**@brief APP driver peripheral wakeup priority define. */
typedef enum {
WAPEUP_PRIORITY_LOW = 1, /**< Wakeup priority low */
WAPEUP_PRIORITY_MID, /**< Wakeup priority mid */
WAPEUP_PRIORITY_HIGH /**< Wakeup priority high */
} wakeup_priority_t;
/** @} */
#ifdef __cplusplus
}
#endif
#endif
/** @} */
/** @} */
/** @} */
@@ -1,116 +0,0 @@
/**
****************************************************************************************
*
* @file app_drv_error.h
* @author BLE Driver Team
* @brief Header file of app driver error code.
*
****************************************************************************************
* @attention
#####Copyright (c) 2019 GOODIX
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of GOODIX nor the names of its contributors may be used
to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
****************************************************************************************
*/
/** @addtogroup PERIPHERAL Peripheral Driver
* @{
*/
/** @addtogroup APP_DRIVER APP DRIVER
* @{
*/
/** @defgroup APP_DRIVER_ERROR ERROR DEFINE
* @brief APP ERROR DEFINE
* @{
*/
#ifndef _APP_DRV_ERROR_H_
#define _APP_DRV_ERROR_H_
#include "gr55xx_hal.h"
#ifdef __cplusplus
extern "C" {
#endif
/**@addtogroup APP_DRV_ERR Defines
* @{
*/
/**@addtogroup APP_DRV_ERR_CODE App Driver error codes
* @{
*/
#define APP_DRV_SUCCESS 0x0000 /**< Successful. */
#define APP_DRV_ERR_HAL 0x0001 /**< Hal internal error. */
#define APP_DRV_ERR_BUSY 0x0002 /**< Driver is busy. */
#define APP_DRV_ERR_TIMEOUT 0x0003 /**< Timeout occurred. */
#define APP_DRV_ERR_INVALID_PARAM 0x0004 /**< Invalid parameter supplied. */
#define APP_DRV_ERR_POINTER_NULL 0x0005 /**< Invalid pointer supplied. */
#define APP_DRV_ERR_INVALID_TYPE 0x0006 /**< Invalid type suplied. */
#define APP_DRV_ERR_INVALID_MODE 0x0007 /**< Invalid mode suplied. */
#define APP_DRV_ERR_INVALID_ID 0x0008 /**< Invalid ID suplied. */
/** @} */
/**@addtogroup APP_DRV_ERR_CODE_CHECK App Driver error code check
* @{
*/
/**@brief App Driver error code check. */
#define APP_DRV_ERR_CODE_CHECK(err_code) \
do \
{ \
if ((err_code) != APP_DRV_SUCCESS) \
{ \
return err_code; \
} \
} while (0)
/** @} */
/**@addtogroup HAL_DRV_ERR_CODE_CHECK Hal Driver error code check
* @{
*/
/**@brief Hal Driver error code check. */
#define HAL_ERR_CODE_CHECK(err_code) \
do \
{ \
if ((err_code) != HAL_OK) \
{ \
return (uint16_t)(err_code); \
} \
} while (0)
/** @} */
/** @} */
#ifdef __cplusplus
}
#endif
#endif
/** @} */
/** @} */
/** @} */
@@ -1,142 +0,0 @@
/**
****************************************************************************************
*
* @file app_gpiote.h
* @author BLE Driver Team
* @brief Header file containing functions prototypes of GPIO Interrupt app library.
*
****************************************************************************************
* @attention
#####Copyright (c) 2019 GOODIX
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of GOODIX nor the names of its contributors may be used
to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
****************************************************************************************
*/
/** @addtogroup PERIPHERAL Peripheral Driver
* @{
*/
/** @addtogroup APP_DRIVER APP DRIVER
* @{
*/
/** @defgroup APP_GPIO_INTERRUPT GPIO INTERRUPT
* @brief GPIO INTERRUPT APP module driver.
* @{
*/
#ifndef _APP_GPIOTE_H_
#define _APP_GPIOTE_H_
#include "app_io.h"
#include "app_drv_error.h"
/** @addtogroup APP_GPIO_INTERRUPT_STRUCTURES Structures
* @{
*/
/**
* @brief GPIO Interrupt event Structure definition
*/
typedef struct {
app_io_type_t type; /**< Type of event. */
uint32_t pin; /**< Specifies the IO pins to be configured. */
app_ctx_type_t ctx_type; /**< Type of handler context. */
} app_gpiote_evt_t;
/**
* @brief GPIOTE input event handler type.
*/
typedef void (*app_gpiote_event_handler_t)(app_gpiote_evt_t *p_evt);
/**
* @brief GPIOTE callback type.
*/
typedef void (*app_io_callback_t)(app_gpiote_evt_t *p_evt);
/**
* @brief GPIOTE Interrupt parameters structure definition
*/
typedef struct {
app_io_type_t type; /**< Specifies IO type */
uint32_t pin; /**< Specifies the IO pins to be configured. */
app_io_mode_t mode; /**< Specifies the IO mode for the selected pins. */
app_io_pull_t pull; /**< Specifies the Pull-up or Pull-Down activation for the selected pins. */
app_handle_mode_t handle_mode; /**< Specifies the IO wakeup mode. */
app_io_callback_t io_evt_cb; /**< IO callback function. */
} app_gpiote_param_t;
/** @} */
/* Exported functions --------------------------------------------------------*/
/** @addtogroup APP_GPIOTE_DRIVER_FUNCTIONS Functions
* @{
*/
/**
****************************************************************************************
* @brief Initialize the APP GPIO Interrupt DRIVER according to the specified parameters
* in the app_gpiote_param_t and app_gpiote_event_handler_t.
*
* @param[in] p_params: Pointer to app_gpiote_param_t parameter which contains the
* configuration information for the specified GPIO.
* @param[in] table_cnt: Used GPIO number.
*
* @return Result of initialization.
****************************************************************************************
*/
uint16_t app_gpiote_init(const app_gpiote_param_t *p_params, uint8_t table_cnt);
/**
****************************************************************************************
* @brief De-initialize the APP GPIO Interrupt DRIVER peripheral.
*
****************************************************************************************
*/
void app_gpiote_deinit(void);
/**
****************************************************************************************
* @brief Config the APP GPIO Interrupt DRIVER according to the specified parameters
* in the app_gpiote_param_t.
*
* @param[in] p_config: Pointer to app_gpiote_param_t parameter which contains the
* configuration information for the specified GPIO.
*
* @return Result of initialization.
****************************************************************************************
*/
uint16_t app_gpiote_config(const app_gpiote_param_t *p_config);
/** @} */
#endif
/** @} */
/** @} */
/** @} */
@@ -1,402 +0,0 @@
/**
****************************************************************************************
*
* @file app_i2c.h
* @author BLE Driver Team
* @brief Header file containing functions prototypes of I2C app library.
*
****************************************************************************************
* @attention
#####Copyright (c) 2019 GOODIX
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of GOODIX nor the names of its contributors may be used
to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
****************************************************************************************
*/
/** @addtogroup PERIPHERAL Peripheral Driver
* @{
*/
/** @addtogroup APP_DRIVER APP DRIVER
* @{
*/
/** @defgroup APP_IIC IIC
* @brief IIC APP module driver.
* @{
*/
#ifndef _APP_I2C_H_
#define _APP_I2C_H_
#include "gr55xx_hal.h"
#include "app_io.h"
#include "app_drv_error.h"
#ifdef ENV_USE_FREERTOS
#include "app_rtos_cfg.h"
#endif
#ifdef __cplusplus
extern "C" {
#endif
#ifdef HAL_I2C_MODULE_ENABLED
/** @addtogroup APP_I2C_ENUM Enumerations
* @{
*/
/**
* @brief I2C module Enumerations definition
*/
typedef enum {
APP_I2C_ID_0, /**< I2C module 0. */
APP_I2C_ID_1, /**< I2C module 1. */
APP_I2C_ID_MAX /**< Only for check parameter, not used as input parameters. */
} app_i2c_id_t;
/**
* @brief I2C role Enumerations definition
*/
typedef enum {
APP_I2C_ROLE_MASTER, /**< I2C master device. */
APP_I2C_ROLE_SLAVE, /**< I2C slave device. */
APP_I2C_ROLE_MAX, /**< Only for check parameter, not used as input parameters. */
} app_i2c_role_t;
/**
* @brief I2C operating mode Enumerations definition
*/
typedef enum {
APP_I2C_TYPE_INTERRUPT, /**< Interrupt operation mode */
APP_I2C_TYPE_POLLING, /**< Polling operation mode */
APP_I2C_TYPE_DMA, /**< DMA operation mode */
APP_I2C_TYPE_MAX, /**< Only for check parameter, not used as input parameters. */
} app_i2c_type_t;
/**
* @brief I2C event Enumerations definition
*/
typedef enum {
APP_I2C_EVT_ERROR, /**< Error reported by I2C peripheral. */
APP_I2C_EVT_TX_CPLT, /**< Requested TX transfer completed. */
APP_I2C_EVT_RX_DATA, /**< Requested RX transfer completed. */
} app_i2c_evt_type_t;
/** @} */
/** @addtogroup APP_I2C_STRUCTURES Structures
* @{
*/
/**
* @brief I2C IO Structures
*/
typedef struct {
app_io_type_t type; /**< Specifies the type of SPI IO. */
app_io_mux_t mux; /**< Specifies the Peripheral to be connected to the selected pins. */
uint32_t pin; /**< Specifies the IO pins to be configured.
This parameter can be any value of @ref GR551x_pins. */
app_io_pull_t pull; /**< Specifies the Pull-up or Pull-Down activation for the selected pins. */
} app_i2c_pin_t;
/**
* @brief I2C IO configuration Structures
*/
typedef struct {
app_i2c_pin_t scl; /**< Set the configuration of I2C SCL pin. */
app_i2c_pin_t sda; /**< Set the configuration of I2C SDA pin. */
} app_i2c_pin_cfg_t;
/**
* @brief I2C operate mode Enumerations definition
*/
typedef struct {
app_i2c_type_t type; /**< Specifies the operation mode of I2C. */
dma_channel_t tx_dma_channel; /**< Specifies the dma channel of I2C TX. */
dma_channel_t rx_dma_channel; /**< Specifies the dma channel of I2C RX. */
} app_i2c_mode_t;
/**
* @brief I2C parameters structure definition
*/
typedef struct {
app_i2c_id_t id; /**< specified I2C module ID. */
app_i2c_role_t role; /**< specified the role of I2C. */
app_i2c_pin_cfg_t pin_cfg; /**< the pin configuration information for the specified I2C module. */
app_i2c_mode_t use_mode; /**< I2C operate mode. */
i2c_init_t init; /**< I2C communication parameters. */
} app_i2c_params_t;
/**
* @brief I2C event structure definition
*/
typedef struct {
app_i2c_evt_type_t type; /**< Type of event. */
union {
uint32_t error_code; /**< I2C Error code . */
uint16_t size; /**< I2C transmitted/received counter. */
} data; /**< I2C data. */
} app_i2c_evt_t;
/**
* @brief I2C event callback definition
*/
typedef void (*app_i2c_evt_handler_t)(app_i2c_evt_t *p_evt);
/** @} */
/* Exported functions --------------------------------------------------------*/
/** @addtogroup HAL_APP_I2C_DRIVER_FUNCTIONS Functions
* @{
*/
/**
****************************************************************************************
* @brief Initialize the APP I2C DRIVER according to the specified parameters
* in the app_i2c_params_t and app_i2c_evt_handler_t.
* @note If interrupt mode is set, you can use blocking mode. Conversely, if blocking mode
* is set, you can't use interrupt mode.
*
* @param[in] p_params: Pointer to app_i2c_params_t parameter which contains the
* configuration information for the specified I2C module.
* @param[in] evt_handler: I2C user callback function.
*
* @return Result of initialization.
****************************************************************************************
*/
uint16_t app_i2c_init(app_i2c_params_t *p_params, app_i2c_evt_handler_t evt_handler);
/**
****************************************************************************************
* @brief De-initialize the APP I2C DRIVER peripheral.
*
* @param[in] id: De-initialize for a specific ID.
*
* @return Result of De-initialization.
****************************************************************************************
*/
uint16_t app_i2c_deinit(app_i2c_id_t id);
/**
****************************************************************************************
* @brief Receive in master or slave mode an amount of data in blocking mode.
*
* @param[in] id: which I2C module want to receive.
* @param[in] target_address: Target device address: The device 7 bits address value in datasheet
must be shifted at right before call interface.
* @param[in] p_data: Pointer to data buffer
* @param[in] size: Amount of data to be sent
* @param[in] timeout: Timeout duration
*
* @return Result of operation.
****************************************************************************************
*/
uint16_t app_i2c_receive_sync(app_i2c_id_t id, uint16_t target_address,
uint8_t *p_data, uint16_t size, uint32_t timeout);
/**
****************************************************************************************
* @brief Receive in master or slave mode an amount of data in non-blocking mode with Interrupt/DMA.
*
* @param[in] id: which I2C module want to receive.
* @param[in] target_address: Target device address: The device 7 bits address value in datasheet
must be shifted at right before call interface.
* @param[in] p_data: Pointer to data buffer
* @param[in] size: Amount of data to be sent
*
* @return Result of operation.
****************************************************************************************
*/
uint16_t app_i2c_receive_async(app_i2c_id_t id, uint16_t target_address, uint8_t *p_data, uint16_t size);
/**
****************************************************************************************
* @brief Transmits in master or slave mode an amount of data in blocking mode.
*
* @param[in] id: which I2C module want to transmit.
* @param[in] target_address: Target device address: The device 7 bits address value in datasheet
must be shifted at right before call interface.
* @param[in] p_data: Pointer to data buffer
* @param[in] size: Amount of data to be sent
* @param[in] timeout: Timeout duration
*
* @return Result of operation.
****************************************************************************************
*/
uint16_t app_i2c_transmit_sync(app_i2c_id_t id, uint16_t target_address,
uint8_t *p_data, uint16_t size, uint32_t timeout);
/**
****************************************************************************************
* @brief Transmits in master or slave mode an amount of data in non-blocking mode with Interrupt/DMA.
*
* @param[in] id: which I2C module want to transmit.
* @param[in] target_address: Target device address: The device 7 bits address value in datasheet
must be shifted at right before call interface.
* @param[in] p_data: Pointer to data buffer
* @param[in] size: Amount of data to be sent
*
* @return Result of operation.
****************************************************************************************
*/
uint16_t app_i2c_transmit_async(app_i2c_id_t id, uint16_t target_address, uint8_t *p_data, uint16_t size);
/**
****************************************************************************************
* @brief Read an amount of data in blocking mode from a specific memory address
*
* @param[in] id: I2C module ID.
* @param[in] dev_address: Target device address: The device 7 bits address value
* in datasheet must be shifted at right before call interface
* @param[in] mem_address: Internal memory address
* @param[in] mem_addr_size: Size of internal memory address
* @param[in] p_data: Pointer to data buffer
* @param[in] size: Amount of data to be sent
* @param[in] timeout: Timeout duration
*
* @return Result of operation.
****************************************************************************************
*/
uint16_t app_i2c_mem_read_sync(app_i2c_id_t id, uint16_t dev_address,
uint16_t mem_address, uint16_t mem_addr_size,
uint8_t *p_data, uint16_t size, uint32_t timeout);
/**
****************************************************************************************
* @brief Read an amount of data in non-blocking mode with Interrupt/DMA from a specific memory address
*
* @param[in] id: I2C module ID.
* @param[in] dev_address: Target device address: The device 7 bits address value in
* datasheet must be shifted at right before call interface
* @param[in] mem_address: Internal memory address
* @param[in] mem_addr_size: Size of internal memory address
* @param[in] p_data: Pointer to data buffer
* @param[in] size: Amount of data to be sent
*
* @return Result of operation.
****************************************************************************************
*/
uint16_t app_i2c_mem_read_async(app_i2c_id_t id, uint16_t dev_address,
uint16_t mem_address, uint16_t mem_addr_size,
uint8_t *p_data, uint16_t size);
/**
****************************************************************************************
* @brief Write an amount of data in blocking mode to a specific memory address
*
* @param[in] id: I2C module ID.
* @param[in] dev_address: Target device address: The device 7 bits address value in
* datasheet must be shifted at right before call interface
* @param[in] mem_address: Internal memory address
* @param[in] mem_addr_size: Size of internal memory address
* @param[in] p_data: Pointer to data buffer
* @param[in] size: Amount of data to be sent
* @param[in] timeout: Timeout duration
*
* @return Result of operation.
****************************************************************************************
*/
uint16_t app_i2c_mem_write_sync(app_i2c_id_t id, uint16_t dev_address,
uint16_t mem_address, uint16_t mem_addr_size,
uint8_t *p_data, uint16_t size, uint32_t timeout);
/**
****************************************************************************************
* @brief Write an amount of data in non-blocking mode with Interrupt/DMA to a specific memory address
*
* @param[in] id: I2C module ID.
* @param[in] dev_address: Target device address: The device 7 bits address value in
* datasheet must be shifted at right before call interface
* @param[in] mem_address: Internal memory address
* @param[in] mem_addr_size: Size of internal memory address
* @param[in] p_data: Pointer to data buffer
* @param[in] size: Amount of data to be sent
*
* @return Result of operation.
****************************************************************************************
*/
uint16_t app_i2c_mem_write_async(app_i2c_id_t id, uint16_t dev_address,
uint16_t mem_address, uint16_t mem_addr_size,
uint8_t *p_data, uint16_t size);
/**
****************************************************************************************
* @brief Return the I2C handle.
*
* @param[in] id: I2C module ID.
*
* @return Pointer to the specified ID's I2C handle.
****************************************************************************************
*/
i2c_handle_t *app_i2c_get_handle(app_i2c_id_t id);
#ifdef ENV_RTOS_USE_SEMP
/**
****************************************************************************************
* @brief [RTOS] Receive in master or slave mode an amount of data in blocking mode.
*
* @param[in] id: I2C module ID.
* @param[in] target_address: Target device address: The device 7 bits address value in datasheet
must be shifted at right before call interface.
* @param[in] p_data: Pointer to data buffer
* @param[in] size: Amount of data to be sent
*
* @return Result of operation.
****************************************************************************************
*/
uint16_t app_i2c_receive_sem_sync(app_i2c_id_t id, uint16_t target_address, uint8_t *p_data, uint16_t size);
/**
****************************************************************************************
* @brief [RTOS] Transmits in master or slave mode an amount of data in blocking mode.
*
* @param[in] id: I2C module ID.
* @param[in] target_address: Target device address: The device 7 bits address value in datasheet
must be shifted at right before call interface.
* @param[in] p_data: Pointer to data buffer
* @param[in] size: Amount of data to be sent
*
* @return Result of operation.
****************************************************************************************
*/
uint16_t app_i2c_transmit_sem_sync(app_i2c_id_t id, uint16_t target_address, uint8_t *p_data, uint16_t size);
#endif
/** @} */
#endif
#ifdef __cplusplus
}
#endif
#endif
/** @} */
/** @} */
/** @} */
@@ -1,302 +0,0 @@
/**
****************************************************************************************
*
* @file app_io.h
* @author BLE Driver Team
* @brief Header file containing functions prototypes of GPIO app library.
*
****************************************************************************************
* @attention
#####Copyright (c) 2019 GOODIX
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of GOODIX nor the names of its contributors may be used
to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
****************************************************************************************
*/
/** @addtogroup PERIPHERAL Peripheral Driver
* @{
*/
/** @addtogroup APP_DRIVER APP DRIVER
* @{
*/
/** @defgroup APP_GPIO GPIO
* @brief GPIO APP module driver.
* @{
*/
#ifndef _APP_IO_H_
#define _APP_IO_H_
#include <stdint.h>
#include "app_drv_error.h"
/** @addtogroup APP_GPIO_PIN_DEFINES Defines
* @{
*/
/** @addtogroup GR551x_pins IO pins
* @{
*/
/**
* @brief APP_GPIO_DEFINE Defines
*/
#define APP_IO_PIN_0 ((uint32_t)0x00000001U) /**< Pin 0 selected */
#define APP_IO_PIN_1 ((uint32_t)0x00000002U) /**< Pin 1 selected */
#define APP_IO_PIN_2 ((uint32_t)0x00000004U) /**< Pin 2 selected */
#define APP_IO_PIN_3 ((uint32_t)0x00000008U) /**< Pin 3 selected */
#define APP_IO_PIN_4 ((uint32_t)0x00000010U) /**< Pin 4 selected */
#define APP_IO_PIN_5 ((uint32_t)0x00000020U) /**< Pin 5 selected */
#define APP_IO_PIN_6 ((uint32_t)0x00000040U) /**< Pin 6 selected */
#define APP_IO_PIN_7 ((uint32_t)0x00000080U) /**< Pin 7 selected */
#define APP_IO_PIN_8 ((uint32_t)0x00000100U) /**< Pin 8 selected */
#define APP_IO_PIN_9 ((uint32_t)0x00000200U) /**< Pin 9 selected */
#define APP_IO_PIN_10 ((uint32_t)0x00000400U) /**< Pin 10 selected */
#define APP_IO_PIN_11 ((uint32_t)0x00000800U) /**< Pin 11 selected */
#define APP_IO_PIN_12 ((uint32_t)0x00001000U) /**< Pin 12 selected */
#define APP_IO_PIN_13 ((uint32_t)0x00002000U) /**< Pin 13 selected */
#define APP_IO_PIN_14 ((uint32_t)0x00004000U) /**< Pin 14 selected */
#define APP_IO_PIN_15 ((uint32_t)0x00008000U) /**< Pin 15 selected */
#define APP_IO_PIN_16 ((uint32_t)0x00010000U) /**< Pin 16 selected */
#define APP_IO_PIN_17 ((uint32_t)0x00020000U) /**< Pin 17 selected */
#define APP_IO_PIN_18 ((uint32_t)0x00040000U) /**< Pin 18 selected */
#define APP_IO_PIN_19 ((uint32_t)0x00080000U) /**< Pin 19 selected */
#define APP_IO_PIN_20 ((uint32_t)0x00100000U) /**< Pin 20 selected */
#define APP_IO_PIN_21 ((uint32_t)0x00200000U) /**< Pin 21 selected */
#define APP_IO_PIN_22 ((uint32_t)0x00400000U) /**< Pin 22 selected */
#define APP_IO_PIN_23 ((uint32_t)0x00800000U) /**< Pin 23 selected */
#define APP_IO_PIN_24 ((uint32_t)0x01000000U) /**< Pin 24 selected */
#define APP_IO_PIN_25 ((uint32_t)0x02000000U) /**< Pin 25 selected */
#define APP_IO_PIN_26 ((uint32_t)0x04000000U) /**< Pin 26 selected */
#define APP_IO_PIN_27 ((uint32_t)0x08000000U) /**< Pin 27 selected */
#define APP_IO_PIN_28 ((uint32_t)0x10000000U) /**< Pin 28 selected */
#define APP_IO_PIN_29 ((uint32_t)0x20000000U) /**< Pin 29 selected */
#define APP_IO_PIN_30 ((uint32_t)0x40000000U) /**< Pin 30 selected */
#define APP_IO_PIN_31 ((uint32_t)0x80000000U) /**< Pin 31 selected */
#define APP_IO_PINS_0_15 ((uint32_t)0x0000FFFFU) /**< 0~15 pins selected */
#define APP_IO_PINS_16_31 ((uint32_t)0xFFFF0000U) /**< 16~31 pins selected */
#define APP_IO_PIN_ALL ((uint32_t)0xFFFFFFFFU) /**< All pins selected */
#define APP_MSIO_PIN_MASK ((uint32_t)0x0000001FU) /**< PIN mask for assert test */
#define APP_MSIO_PIN_ALL ((uint32_t)0x001FU) /**< All pins selected */
#define APP_AON_IO_PIN_MASK ((uint32_t)0x000000FFU) /**< PIN mask for assert test */
#define APP_AON_IO_PIN_ALL ((uint32_t)0x00FFU) /**< All pins selected */
#define APP_IO_PIN_MASK ((uint32_t)0xFFFFFFFFU) /**< PIN mask for assert test */
/**
* @brief GR551x_APP_GPIO_default_config initStruct default configuart APP_GPIOn
*/
#define APP_IO_DEFAULT_CONFIG \
{ \
.pin = APP_IO_PIN_ALL, \
.mode = APP_IO_MODE_INPUT, \
.pull = APP_IO_PULLDOWN, \
.mux = APP_IO_MUX_7, \
}
/** @} */
/** @} */
/** @addtogroup APP_GPIO_ENUMERATIONS Enumerations
* @{
*/
/**
* @brief GPIO state Enumerations definition
*/
typedef enum {
APP_IO_PIN_RESET, /**< IO pin low level. */
APP_IO_PIN_SET, /**< IO pin high level. */
} app_io_pin_state_t;
/**
* @brief GPIO type Enumerations definition
*/
typedef enum {
APP_IO_TYPE_NORMAL, /**< General Purpose Input/Output. */
APP_IO_TYPE_AON, /**< Always-on Input/Output. */
APP_IO_TYPE_MSIO, /**< Mixed Signal I/O. */
APP_IO_TYPE_MAX, /**< Only for check parameter, not used as input parameters. */
} app_io_type_t;
/**
* @brief GPIO mode Enumerations definition
*/
typedef enum {
APP_IO_MODE_INPUT, /**< Input Mode. */
APP_IO_MODE_OUT_PUT, /**< Output Mode. */
APP_IO_MODE_MUX, /**< Mux Mode. */
APP_IO_MODE_IT_RISING, /**< Interrupt Mode with Rising edge trigger detection. */
APP_IO_MODE_IT_FALLING, /**< Interrupt Mode with Falling edge trigger detection. */
APP_IO_MODE_IT_HIGH, /**< Interrupt Mode with High-level trigger detection. */
APP_IO_MODE_IT_LOW, /**< Interrupt Mode with Low-level trigger detection. */
APP_IO_MODE_ANALOG, /**< Analog IO Mode. */
APP_IO_MODE_MAX, /**< Only for check parameter, not used as input parameters. */
} app_io_mode_t;
/**
* @brief GPIO wake-up mode Enumerations definition
*/
typedef enum {
APP_IO_NONE_WAKEUP, /**< None Wakeup. */
APP_IO_DISABLE_WAKEUP, /**< Disable AON GPIO Wakeup. */
APP_IO_ENABLE_WAKEUP, /**< Enable AON GPIO Wakeup. */
} app_handle_mode_t;
/**
* @brief GPIO handler context type Enumerations definition
*/
typedef enum {
APP_IO_CTX_WAKEUP, /**< the event of wakeup. */
APP_IO_CTX_INT, /**< the event of interrupt. */
} app_ctx_type_t;
/**
* @brief GPIO pull Enumerations definition
*/
typedef enum {
APP_IO_NOPULL, /**< No Pull-up or Pull-down activation. */
APP_IO_PULLUP, /**< Pull-up activation. */
APP_IO_PULLDOWN, /**< Pull-down activation. */
APP_IO_PULL_MAX /**< Only for check parameter, not used as input parameters. */
} app_io_pull_t;
/**
* @brief GPIO mux Enumerations definition
*/
typedef enum {
APP_IO_MUX_0, /**< IO mux mode 0. */
APP_IO_MUX_1, /**< IO mux mode 1. */
APP_IO_MUX_2, /**< IO mux mode 2. */
APP_IO_MUX_3, /**< IO mux mode 3. */
APP_IO_MUX_4, /**< IO mux mode 4. */
APP_IO_MUX_5, /**< IO mux mode 5. */
APP_IO_MUX_6, /**< IO mux mode 6. */
APP_IO_MUX_7, /**< IO mux mode 7. */
APP_IO_MUX_8, /**< IO mux mode 8. */
APP_IO_MUX_MAX, /**< Only for check parameter, not used as input parameters. */
} app_io_mux_t;
/** @} */
/** @addtogroup APP_GPIO_STRUCT Structures
* @{
*/
/**
* @brief GPIO parameter structure definition
*/
typedef struct {
uint32_t pin; /**< Specifies the IO pins to be configured.
This parameter can be any value of @ref GR551x_pins */
app_io_mode_t mode; /**< Specifies the operating mode for the selected pins. */
app_io_pull_t pull; /**< Specifies the Pull-up or Pull-Down activation for the selected pins. */
app_io_mux_t mux; /**< Specifies the Peripheral to be connected to the selected pins. */
} app_io_init_t;
/** @} */
/* Exported functions --------------------------------------------------------*/
/** @addtogroup HAL_APP_GPIO_DRIVER_FUNCTIONS Functions
* @{
*/
/**
****************************************************************************************
* @brief Initialize the APP GPIO DRIVER according to the specified parameters
* in the app_io_type_t and app_io_init_t.
*
* @param[in] type: GPIO type.
* @param[in] p_init: Pointer to app_io_init_t parameter which contains the
* configuration information for the specified GPIO.
*
* @return Result of initialization.
****************************************************************************************
*/
uint16_t app_io_init(app_io_type_t type, app_io_init_t *p_init);
/**
****************************************************************************************
* @brief De-initialize the GPIOx peripheral.
*
* @param[in] type: GPIO type, See app_io_type_t.
* @param[in] pin: The pin want to De-initialization.
*
* @return Result of De-initialization.
****************************************************************************************
*/
uint16_t app_io_deinit(app_io_type_t type, uint32_t pin);
/**
****************************************************************************************
* @brief Read the specified input port pin..
*
* @param[in] type: GPIO type, See app_io_type_t.
* @param[in] pin: The pin want to read.
*
* @return The GPIO state.
****************************************************************************************
*/
app_io_pin_state_t app_io_read_pin(app_io_type_t type, uint32_t pin);
/**
****************************************************************************************
* @brief Set or clear the selected data port bit.
*
* @param[in] type: GPIO type, See app_io_type_t.
* @param[in] pin: The pin want to set or clear.
* @param[in] pin_state: Specifies the value to be written to the selected bit.
*
* @return Result of write.
****************************************************************************************
*/
uint16_t app_io_write_pin(app_io_type_t type, uint32_t pin, app_io_pin_state_t pin_state);
/**
****************************************************************************************
* @brief Toggle the specified GPIO pin.
*
* @param[in] type: GPIO type, See app_io_type_t.
* @param[in] pin: The pin want to toggle.
*
* @return Result of toggle.
****************************************************************************************
*/
uint16_t app_io_toggle_pin(app_io_type_t type, uint32_t pin);
/** @} */
uint16_t app_io_toggle_pin_sym(app_io_type_t type, uint32_t pin);
uint16_t app_io_write_pin_sym(app_io_type_t type, uint32_t pin, app_io_pin_state_t pin_state);
app_io_pin_state_t app_io_read_pin_sym(app_io_type_t type, uint32_t pin);
uint16_t app_io_deinit_sym(app_io_type_t type, uint32_t pin);
uint16_t app_io_init_sym(app_io_type_t type, app_io_init_t *p_init);
#endif
/** @} */
/** @} */
/** @} */
@@ -1,244 +0,0 @@
/**
****************************************************************************************
*
* @file app_pwm.h
* @author BLE Driver Team
* @brief Header file containing functions prototypes of PWM app library.
*
****************************************************************************************
* @attention
#####Copyright (c) 2019 GOODIX
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of GOODIX nor the names of its contributors may be used
to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
****************************************************************************************
*/
/** @addtogroup PERIPHERAL Peripheral Driver
* @{
*/
/** @addtogroup APP_DRIVER APP DRIVER
* @{
*/
/** @defgroup APP_PWM PWM
* @brief PWM APP module driver.
* @{
*/
#ifndef _APP_PWM_H_
#define _APP_PWM_H_
#include "gr55xx_hal.h"
#include "app_io.h"
#include "app_drv_error.h"
#ifdef __cplusplus
extern "C" {
#endif
#ifdef HAL_PWM_MODULE_ENABLED
/** @addtogroup APP_PWM_DEFINE Defines
* @{
*/
#define APP_PWM_PIN_ENABLE 1 /**< PWM pin enable */
#define APP_PWM_PIN_DISABLE 0 /**< PWM pin disable */
/** @} */
/** @addtogroup APP_PWM_ENUM Enumerations
* @{
*/
/**
* @brief PWM module Enumerations definition
*/
typedef enum {
APP_PWM_ID_0, /**< PWM module 0 */
APP_PWM_ID_1, /**< PWM module 1 */
APP_PWM_ID_MAX /**< Only for check parameter, not used as input parameters. */
} app_pwm_id_t;
/** @} */
/** @addtogroup APP_PWM_STRUCTURES Structures
* @{
*/
/**
* @brief PWM IO configuration Structures
*/
typedef struct {
app_io_type_t type; /**< Specifies the type of PWM IO. */
app_io_mux_t mux; /**< Specifies the Peripheral to be connected to the selected pins. */
uint32_t pin; /**< Specifies the IO pins to be configured.
This parameter can be any value of @ref GR551x_pins. */
app_io_pull_t pull; /**< Specifies the Pull-up or Pull-Down activation for the selected pins. */
uint8_t enable; /**< Enable or disable the pin. */
} app_pwm_pin_t;
/**
* @brief PWM configuration Structures
*/
typedef struct {
app_pwm_pin_t channel_a; /**< Set the configuration of PWM channel A pin. */
app_pwm_pin_t channel_b; /**< Set the configuration of PWM channel B pin. */
app_pwm_pin_t channel_c; /**< Set the configuration of PWM channel C pin. */
} app_pwm_pin_cfg_t;
/**
* @brief PWM Channel init Structure definition
*/
typedef struct {
uint8_t duty; /**< Specifies the duty in PWM output mode.
This parameter must be a number between 0 ~ 100. */
uint8_t drive_polarity; /**< Specifies the drive polarity in PWM output mode.
This parameter can be a value of @ref PWM_Drive_Polarity. */
} app_pwm_channel_init_t;
/** @} */
/** @addtogroup APP_PWM_ENUM Enumerations
* @{
*/
/**
* @brief PWM active channel Enumerations definition
*/
typedef enum {
APP_PWM_ACTIVE_CHANNEL_A = 0x01, /**< The active channel is A */
APP_PWM_ACTIVE_CHANNEL_B = 0x02, /**< The active channel is B */
APP_PWM_ACTIVE_CHANNEL_C = 0x04, /**< The active channel is C */
APP_PWM_ACTIVE_CHANNEL_ALL = 0x07, /**< The active channels are ALL */
APP_PWM_ACTIVE_CHANNEL_CLEARED = 0x00 /**< All active channels are cleared */
} app_pwm_active_channel_t;
/** @} */
/** @addtogroup APP_PWM_STRUCTURES Structures
* @{
*/
/**
* @brief PWM parameters structure definition
*/
typedef struct {
app_pwm_id_t id; /**< specified PWM module ID. */
app_pwm_pin_cfg_t pin_cfg; /**< the pin configuration information for the specified PWM module. */
app_pwm_active_channel_t active_channel; /**< PWM operate mode. */
pwm_init_t init; /**< PWM communication parameters. */
} app_pwm_params_t;
/** @} */
/* Exported functions --------------------------------------------------------*/
/** @addtogroup APP_PWM_DRIVER_FUNCTIONS Functions
* @{
*/
/**
****************************************************************************************
* @brief Initialize the pwm peripheral.
*
* @param[in] p_params: Pointer to app_pwm_params_t parameter which contains the
* configuration information for the specified PWM module.
*
* @return Result of initialization.
****************************************************************************************
*/
uint16_t app_pwm_init(app_pwm_params_t *p_params);
/**
****************************************************************************************
* @brief De-initialize the pwm peripheral.
*
* @param[in] id: De-initialize for a specific ID.
*
* @return Result of De-initialization.
****************************************************************************************
*/
uint16_t app_pwm_deinit(app_pwm_id_t id);
/**
****************************************************************************************
* @brief Starts the PWM signal generation on the output.
*
* @param[in] id: which PWM module want to output.
*
* @return Result of operation.
****************************************************************************************
*/
uint16_t app_pwm_start(app_pwm_id_t id);
/**
****************************************************************************************
* @brief Stops the PWM signal generation on the output.
*
* @param[in] id: which PWM module want to stop output.
*
* @return Result of operation.
****************************************************************************************
*/
uint16_t app_pwm_stop(app_pwm_id_t id);
/**
****************************************************************************************
* @brief Update the PWM frequency on the output.
*
* @param[in] id: which PWM module want to config.
* @param[in] freq: This parameter ranges between min = 0 and max = SystemFreq / 2.
*
* @return Result of operation.
****************************************************************************************
*/
uint16_t app_pwm_update_freq(app_pwm_id_t id, uint32_t freq);
/**
****************************************************************************************
* @brief Initialize the PWM channels according to the specified parameters.
*
* @param[in] id: which PWM module want to config.
* @param[in] channel: PWM Channels to be configured.
* @param[in] p_config: PWM Channels configuration structure.
*
* @return Result of operation.
****************************************************************************************
*/
uint16_t app_pwm_config_channel(app_pwm_id_t id, app_pwm_active_channel_t channel, app_pwm_channel_init_t *p_config);
/** @} */
#endif
#ifdef __cplusplus
}
#endif
#endif
/** @} */
/** @} */
/** @} */
@@ -1,122 +0,0 @@
/**
****************************************************************************************
*
* @file app_pwr_mgmt.h
* @author BLE Driver Team
* @brief Header file containing functions prototypes of UART PWR library.
*
****************************************************************************************
* @attention
#####Copyright (c) 2019 GOODIX
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of GOODIX nor the names of its contributors may be used
to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
****************************************************************************************
*/
/** @addtogroup PERIPHERAL Peripheral Driver
* @{
*/
/** @addtogroup APP_DRIVER APP DRIVER
* @{
*/
/** @defgroup APP_PWR_MGMT PWR MGMT
* @brief PWR MGMT APP module driver.
* @{
*/
#ifndef _APP_PWR_MGMT_H_
#define _APP_PWR_MGMT_H_
#include <stdint.h>
#include <stdbool.h>
#include "app_drv_config.h"
#include "gr55xx_pwr.h"
/** @addtogroup APP_PWR_DEFINE Defines
* @{
*/
/**
* @brief PWR MAX value for sleep check
*/
#define APP_SLEEP_CB_MAX 16
/** @} */
/**
* @brief PWR sleep check function Structure
*/
typedef struct {
bool (*app_prepare_for_sleep)(void); /**<Peripherals prepare sleep fuction . */
void (*app_sleep_canceled)(void); /**<Peripherals cancel sleep fuction . */
void (*app_wake_up_ind)(void); /**< Resume peripherals when used fuctioin . */
} app_sleep_callbacks_t;
/** @} */
/* Exported functions --------------------------------------------------------*/
/** @addtogroup APP_PWR_DRIVER_FUNCTIONS Functions
* @{
*/
/**
****************************************************************************************
* @brief set PWR sleep callback function
* @param p_cb : Device check callback function
* @param wakeup_priority : Device wakeup priority
*
* @return ID
****************************************************************************************
*/
int16_t pwr_register_sleep_cb(const app_sleep_callbacks_t *p_cb, wakeup_priority_t wakeup_priority);
/**
****************************************************************************************
* @brief Unregister PWR sleep callback function
* @param id : which id want to unregister
****************************************************************************************
*/
void pwr_unregister_sleep_cb(int16_t id);
/**
****************************************************************************************
* @brief Things to do after waking up.
****************************************************************************************
*/
void pwr_wake_up_ind(void);
/**
****************************************************************************************
* @brief Check peripheral status before going to sleep.
****************************************************************************************
*/
pwr_mgmt_dev_state_t pwr_enter_sleep_check(void);
/** @} */
#endif
/** @} */
/** @} */
/** @} */
@@ -1,526 +0,0 @@
/**
****************************************************************************************
*
* @file app_qspi.h
* @author BLE Driver Team
* @brief Header file containing functions prototypes of QSPI app library.
*
****************************************************************************************
* @attention
#####Copyright (c) 2019 GOODIX
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of GOODIX nor the names of its contributors may be used
to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
****************************************************************************************
*/
/** @addtogroup PERIPHERAL Peripheral Driver
* @{
*/
/** @addtogroup APP_DRIVER APP DRIVER
* @{
*/
/** @defgroup APP_QSPI QSPI
* @brief QSPI APP module driver.
* @{
*/
#ifndef _APP_QSPI_H_
#define _APP_QSPI_H_
#include "gr55xx_hal.h"
#include "app_io.h"
#include "app_drv_error.h"
#include "app_rtos_cfg.h"
#ifdef __cplusplus
extern "C" {
#endif
#ifdef HAL_QSPI_MODULE_ENABLED
/** @addtogroup APP_QSPI_DEFINE Defines
* @{
*/
#define APP_QSPI_PIN_ENABLE 1 /**< QSPI pin enable */
#define APP_QSPI_PIN_DISABLE 0 /**< QSPI pin disable */
/** @} */
/** @addtogroup APP_QSPI_ENUM Enumerations
* @{
*/
/**
* @brief QSPI module Enumerations definition
*/
typedef enum {
APP_QSPI_ID_0, /**< QSPI module 0 */
APP_QSPI_ID_1, /**< QSPI module 1 */
APP_QSPI_ID_MAX /**< Only for check parameter, not used as input parameters. */
} app_qspi_id_t;
/**
* @brief QSPI operating mode Enumerations definition
*/
typedef enum {
APP_QSPI_TYPE_INTERRUPT, /**< Interrupt operation mode */
APP_QSPI_TYPE_POLLING, /**< Polling operation mode */
APP_QSPI_TYPE_DMA, /**< DMA operation mode */
APP_QSPI_TYPE_MAX, /**< Only for check parameter, not used as input parameters. */
} app_qspi_type_t;
/**
* @brief APP QSPI Event Type
*/
typedef enum {
APP_QSPI_EVT_ERROR, /**< Error reported by UART peripheral. */
APP_QSPI_EVT_TX_CPLT, /**< Requested TX transfer completed. */
APP_QSPI_EVT_RX_DATA, /**< Requested RX transfer completed. */
} app_qspi_evt_type_t;
/** @} */
/** @addtogroup APP_QSPI_STRUCTURES Structures
* @{
*/
/**
* @brief QSPI IO configuration Structures
*/
typedef struct {
app_io_type_t type; /**< Specifies the type of QSPI IO. */
app_io_mux_t mux; /**< Specifies the Peripheral to be connected to the selected pins. */
uint32_t pin; /**< Specifies the IO pins to be configured.
This parameter can be any value of @ref GR551x_pins. */
app_io_pull_t pull; /**< Specifies the Pull-up or Pull-Down activation for the selected pins. */
uint8_t enable; /**< Enable or disable the pin. */
} app_qspi_pin_t;
/**
* @brief QSPI configuration Structures
*/
typedef struct {
app_qspi_pin_t cs; /**< Set the configuration of QSPI CS pin. */
app_qspi_pin_t clk; /**< Set the configuration of QSPI CLK pin. */
app_qspi_pin_t io_0; /**< Set the configuration of QSPI IO0 pin. */
app_qspi_pin_t io_1; /**< Set the configuration of QSPI IO1 pin. */
app_qspi_pin_t io_2; /**< Set the configuration of QSPI IO2 pin. */
app_qspi_pin_t io_3; /**< Set the configuration of QSPI IO3 pin. */
} app_qspi_pin_cfg_t;
/**
* @brief QSPI operate mode Enumerations definition
*/
typedef struct {
app_qspi_type_t type; /**< Specifies the operation mode of QSPI. */
dma_channel_t dma_channel; /**< Specifies the dma channel of QSPI. */
} app_qspi_mode_t;
/**
* @brief QSPI parameters structure definition
*/
typedef struct {
app_qspi_id_t id; /**< specified QSPI module ID. */
app_qspi_pin_cfg_t pin_cfg; /**< the pin configuration information for the specified QSPI module. */
app_qspi_mode_t use_mode; /**< QSPI operate mode. */
qspi_init_t init; /**< QSPI communication parameters. */
} app_qspi_params_t;
/** @} */
/** @addtogroup APP_QSPI_TYPEDEFS Typedefs
* @{
*/
/**
* @brief QSPI command structure definition
*/
typedef qspi_command_t app_qspi_command_t;
/** @} */
/** @addtogroup APP_QSPI_STRUCTURES Structures
* @{
*/
/**
* @brief QSPI event structure definition
*/
typedef struct {
app_qspi_evt_type_t type; /**< Type of event. */
union {
uint32_t error_code; /**< QSPI Error code . */
uint16_t size; /**< QSPI transmitted/received counter. */
} data; /**< Event data. */
} app_qspi_evt_t;
/** @} */
/** @addtogroup APP_QSPI_TYPEDEFS Typedefs
* @{
*/
/**
* @brief QSPI event callback definition
*/
typedef void (*app_qspi_evt_handler_t)(app_qspi_evt_t *p_evt);
/** @} */
/* Exported functions --------------------------------------------------------*/
/** @addtogroup HAL_APP_QSPI_DRIVER_FUNCTIONS Functions
* @{
*/
/**
****************************************************************************************
* @brief Initialize the APP QSPI DRIVER according to the specified parameters
* in the app_qspi_params_t and app_qspi_evt_handler_t.
* @note If interrupt mode is set, you can use blocking mode. Conversely, if blocking mode
* is set, you can't use interrupt mode.
*
* @param[in] p_params: Pointer to app_qspi_params_t parameter which contains the
* configuration information for the specified QSPI module.
* @param[in] evt_handler: QSPI user callback function.
*
* @return Result of initialization.
****************************************************************************************
*/
uint16_t app_qspi_init(app_qspi_params_t *p_params, app_qspi_evt_handler_t evt_handler);
/**
****************************************************************************************
* @brief De-initialize the APP QSPI DRIVER peripheral.
*
* @param[in] id: De-initialize for a specific ID.
*
* @return Result of De-initialization.
****************************************************************************************
*/
uint16_t app_qspi_deinit(app_qspi_id_t id);
/**
****************************************************************************************
* @brief Receive an amount of data with the specified instruction, address and dummy cycles in blocking mode.
* @note This function is used only in Indirect Read Mode.
* @param[in] id: which QSPI module want to receive.
* @param[in] p_cmd: Pointer to a app_qspi_command_t structure that
* contains the instruction and address for data transfer.
* @param[out] p_data: Pointer to data buffer
* @param[in] timeout: Timeout duration
*
* @return Result of operation.
****************************************************************************************
*/
uint16_t app_qspi_command_receive_sync(app_qspi_id_t id, app_qspi_command_t *p_cmd, uint8_t *p_data, uint32_t timeout);
/**
****************************************************************************************
* @brief Receive an amount of data with the specified instruction,
* address and dummy cycles in non-blocking mode with Interrupt.
* @note This function is used only in Indirect Read Mode.
* @param[in] id: which QSPI module want to receive.
* @param[in] p_cmd: Pointer to a app_qspi_command_t structure that
* contains the instruction and address for data transfer.
* @param[out] p_data: Pointer to data buffer
*
* @return Result of operation.
****************************************************************************************
*/
uint16_t app_qspi_command_receive_async(app_qspi_id_t id, app_qspi_command_t *p_cmd, uint8_t *p_data);
/**
****************************************************************************************
* @brief Receive an amount of data with the specified instruction, address and dummy cycles in blocking mode.
* @note This function is used only in Indirect Read Mode.
* @param[in] id: which QSPI module want to transmit.
* @param[in] p_cmd: Pointer to a app_qspi_command_t structure that
* contains the instruction and address for data transfer.
* @param[out] p_data: Pointer to data buffer
* @param[in] timeout: Timeout duration
*
* @return Result of operation.
****************************************************************************************
*/
uint16_t app_qspi_command_transmit_sync(app_qspi_id_t id, app_qspi_command_t *p_cmd, uint8_t *p_data, uint32_t timeout);
/**
****************************************************************************************
* @brief Receive an amount of data with the specified instruction,
* address and dummy cycles in non-blocking mode with Interrupt.
* @note This function is used only in Indirect Read Mode.
* @param[in] id: which QSPI module want to transmit.
* @param[in] p_cmd: Pointer to a app_qspi_command_t structure that
* contains the instruction and address for data transfer.
* @param[out] p_data: Pointer to data buffer
*
* @return Result of operation.
****************************************************************************************
*/
uint16_t app_qspi_command_transmit_async(app_qspi_id_t id, app_qspi_command_t *p_cmd, uint8_t *p_data);
/**
****************************************************************************************
* @brief Transmit only instruction in blocking mode.
* @note This function is used only in Indirect Write Mode.
* @param[in] id: which QSPI module want to transmit command.
* @param[in] p_cmd: Pointer to a app_qspi_command_t structure that
* contains the instruction and address for data transfer.
* @param[in] timeout: Timeout duration
*
* @return Result of operation.
****************************************************************************************
*/
uint16_t app_qspi_command_sync(app_qspi_id_t id, app_qspi_command_t *p_cmd, uint32_t timeout);
/**
****************************************************************************************
* @brief Transmit instruction in non-blocking mode with Interrupt.
* @note This function is used only in Indirect Write Mode.
* @param[in] id: which QSPI module want to transmit command.
* @param[in] p_cmd: Pointer to a app_qspi_command_t structure that
* contains the instruction and address for data transfer.
*
* @return Result of operation.
****************************************************************************************
*/
uint16_t app_qspi_command_async(app_qspi_id_t id, app_qspi_command_t *p_cmd);
/**
****************************************************************************************
* @brief Transmit an amount of data in blocking mode with standard SPI.
* @note This function is used only in Indirect Write Mode.
* @param[in] id: which QSPI module want to transmit.
* @param[in] p_data: Pointer to data buffer
* @param[in] length: Amount of data to be sent in bytes
* @param[in] timeout: Timeout duration
*
* @return Result of operation.
****************************************************************************************
*/
uint16_t app_qspi_transmit_sync(app_qspi_id_t id, uint8_t *p_data, uint32_t length, uint32_t timeout);
/**
****************************************************************************************
* @brief Transmit an amount of data in non-blocking mode at standard SPI with Interrupt.
* @note This function is used only in Indirect Write Mode.
* @param[in] id: which QSPI module want to transmit.
* @param[in] p_data: Pointer to data buffer
* @param[in] length: Amount of data to be sent in bytes
*
* @return Result of operation.
****************************************************************************************
*/
uint16_t app_qspi_transmit_async(app_qspi_id_t id, uint8_t *p_data, uint32_t length);
/**
****************************************************************************************
* @brief Receive an amount of data in blocking mode with standard SPI.
* @note This function is used only in Indirect Read Mode.
* @param[in] id: which QSPI module want to receive.
* @param[out] p_data: Pointer to data buffer
* @param[in] length: Amount of data to be received in bytes
* @param[in] timeout: Timeout duration
*
* @return Result of operation.
****************************************************************************************
*/
uint16_t app_qspi_receive_sync(app_qspi_id_t id, uint8_t *p_data, uint32_t length, uint32_t timeout);
/**
****************************************************************************************
* @brief Receive an amount of data in non-blocking mode at standard SPI with Interrupt.
* @note This function is used only in Indirect Read Mode.
* @param[in] id: which QSPI module want to receive.
* @param[out] p_data: Pointer to data buffer
* @param[in] length: Amount of data to be received in bytes
*
* @return Result of operation.
****************************************************************************************
*/
uint16_t app_qspi_receive_async(app_qspi_id_t id, uint8_t *p_data, uint32_t length);
/**
****************************************************************************************
* @brief Return the QSPI handle.
*
* @param[in] id: QSPI Channel ID.
*
* @return Pointer to the specified ID's QSPI handle.
****************************************************************************************
*/
qspi_handle_t *app_qspi_get_handle(app_qspi_id_t id);
#ifdef ENV_RTOS_USE_SEMP
/**
****************************************************************************************
* @brief [RTOS] Receive an amount of data with the specified instruction, address and dummy cycles in blocking mode.
* @note This function is used only in Indirect Read Mode.
* @param[in] id: which QSPI module want to receive.
* @param[in] p_cmd: Pointer to a app_qspi_command_t structure that
* contains the instruction and address for data transfer.
* @param[out] p_data: Pointer to data buffer
*
* @return Result of operation.
****************************************************************************************
*/
uint16_t app_qspi_command_receive_sem_sync(app_qspi_id_t id, app_qspi_command_t *p_cmd, uint8_t *p_data);
/**
****************************************************************************************
* @brief [RTOS] Receive an amount of data with the specified instruction, address and dummy cycles in blocking mode.
* @note This function is used only in Indirect Read Mode.
* @param[in] id: which QSPI module want to transmit.
* @param[in] p_cmd: Pointer to a app_qspi_command_t structure that
* contains the instruction and address for data transfer.
* @param[out] p_data: Pointer to data buffer
*
* @return Result of operation.
****************************************************************************************
*/
uint16_t app_qspi_command_transmit_sem_sync(app_qspi_id_t id, app_qspi_command_t *p_cmd, uint8_t *p_data);
/**
****************************************************************************************
* @brief [RTOS] Transmit only instruction in blocking mode.
* @note This function is used only in Indirect Write Mode.
* @param[in] id: which QSPI module want to transmit command.
* @param[in] p_cmd: Pointer to a app_qspi_command_t structure that
* contains the instruction and address for data transfer.
*
* @return Result of operation.
****************************************************************************************
*/
uint16_t app_qspi_command_sem_sync(app_qspi_id_t id, app_qspi_command_t *p_cmd);
/**
****************************************************************************************
* @brief [RTOS] Transmit an amount of data in blocking mode with standard SPI.
* @note This function is used only in Indirect Write Mode.
* @param[in] id: which QSPI module want to transmit.
* @param[in] p_data: Pointer to data buffer
* @param[in] length: Amount of data to be sent in bytes
*
* @return Result of operation.
****************************************************************************************
*/
uint16_t app_qspi_transmit_sem_sync(app_qspi_id_t id, uint8_t *p_data, uint32_t length);
/**
****************************************************************************************
* @brief [RTOS] Receive an amount of data in blocking mode with standard SPI.
* @note This function is used only in Indirect Read Mode.
* @param[in] id: which QSPI module want to receive.
* @param[out] p_data: Pointer to data buffer
* @param[in] length: Amount of data to be received in bytes
*
* @return Result of operation.
****************************************************************************************
*/
uint16_t app_qspi_receive_sem_sync(app_qspi_id_t id, uint8_t *p_data, uint32_t length);
#endif
/**
****************************************************************************************
* @brief [High speed] Receive an amount of data with
* the specified instruction, address and dummy cycles in blocking mode.
* @note This function is used only in Indirect Read Mode.
* @param[in] id: which QSPI module want to receive.
* @param[in] p_cmd: Pointer to a app_qspi_command_t structure that
* contains the instruction and address for data transfer.
* @param[out] p_data: Pointer to data buffer
*
* @return Result of operation.
****************************************************************************************
*/
uint16_t app_qspi_command_receive_high_speed_sync(app_qspi_id_t id, app_qspi_command_t *p_cmd, uint8_t *p_data);
/**
****************************************************************************************
* @brief [High speed] Receive an amount of data with
* the specified instruction, address and dummy cycles in blocking mode.
* @note This function is used only in Indirect Read Mode.
* @param[in] id: which QSPI module want to transmit.
* @param[in] p_cmd: Pointer to a app_qspi_command_t structure that
* contains the instruction and address for data transfer.
* @param[out] p_data: Pointer to data buffer
*
* @return Result of operation.
****************************************************************************************
*/
uint16_t app_qspi_command_transmit_high_speed_sync(app_qspi_id_t id, app_qspi_command_t *p_cmd, uint8_t *p_data);
/**
****************************************************************************************
* @brief [High speed] Transmit only instruction in blocking mode.
* @note This function is used only in Indirect Write Mode.
* @param[in] id: which QSPI module want to transmit command.
* @param[in] p_cmd: Pointer to a app_qspi_command_t structure that
* contains the instruction and address for data transfer.
*
* @return Result of operation.
****************************************************************************************
*/
uint16_t app_qspi_command_high_speed_sync(app_qspi_id_t id, app_qspi_command_t *p_cmd);
/**
****************************************************************************************
* @brief [High speed] Transmit an amount of data in blocking mode with standard SPI.
* @note This function is used only in Indirect Write Mode.
* @param[in] id: which QSPI module want to transmit.
* @param[in] p_data: Pointer to data buffer
* @param[in] length: Amount of data to be sent in bytes
*
* @return Result of operation.
****************************************************************************************
*/
uint16_t app_qspi_transmit_high_speed_sync(app_qspi_id_t id, uint8_t *p_data, uint32_t length);
/**
****************************************************************************************
* @brief [High speed] Receive an amount of data in blocking mode with standard SPI.
* @note This function is used only in Indirect Read Mode.
* @param[in] id: which QSPI module want to receive.
* @param[out] p_data: Pointer to data buffer
* @param[in] length: Amount of data to be received in bytes
*
* @return Result of operation.
****************************************************************************************
*/
uint16_t app_qspi_receive_high_speed_sync(app_qspi_id_t id, uint8_t *p_data, uint32_t length);
/** @} */
#endif
#ifdef __cplusplus
}
#endif
#endif
/** @} */
/** @} */
/** @} */
@@ -1,213 +0,0 @@
/**
****************************************************************************************
*
* @file app_rng.h
* @author BLE Driver Team
* @brief Header file containing functions prototypes of RNG app library.
*
****************************************************************************************
* @attention
#####Copyright (c) 2019 GOODIX
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of GOODIX nor the names of its contributors may be used
to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
****************************************************************************************
*/
/** @addtogroup PERIPHERAL Peripheral Driver
* @{
*/
/** @addtogroup APP_DRIVER APP DRIVER
* @{
*/
/** @defgroup APP_RNG RNG
* @brief RNG APP module driver.
* @{
*/
#ifndef _APP_RNG_H_
#define _APP_RNG_H_
#include "gr55xx_hal.h"
#include "app_drv_error.h"
#ifdef ENV_USE_FREERTOS
#include "app_rtos_cfg.h"
#endif
#ifdef __cplusplus
extern "C" {
#endif
#ifdef HAL_RNG_MODULE_ENABLED
/** @addtogroup APP_RNG_ENUM Enumerations
* @{
*/
/**
* @brief RNG operating mode Enumerations definition
*/
typedef enum {
APP_RNG_TYPE_INTERRUPT, /**< Interrupt operation mode */
APP_RNG_TYPE_POLLING, /**< Polling operation mode */
APP_RNG_TYPE_MAX /**< Only for check parameter, not used as input parameters. */
} app_rng_type_t;
/**
* @brief RNG event Enumerations definition
*/
typedef enum {
APP_RNG_EVT_DONE, /**< Generated random by UART peripheral. */
APP_RNG_EVT_ERROR, /**< Error reported by UART peripheral. */
} app_rng_evt_type_t;
/** @} */
/** @addtogroup HAL_APP_RNG_STRUCTURES Structures
* @{
*/
/**
* @brief RNG parameters structure definition
*/
typedef struct {
app_rng_type_t use_type; /**< Specifies the operation mode of RNG. */
rng_init_t init; /**< RNG required parameters. */
} app_rng_params_t;
/**
* @brief RNG event structure definition
*/
typedef struct {
app_rng_evt_type_t type; /**< Type of event. */
uint32_t random_data; /**< Random number. */
} app_rng_evt_t;
/**
* @brief RNG event callback definition
*/
typedef void (*app_rng_evt_handler_t)(app_rng_evt_t *p_evt);
/** @} */
/* Exported functions --------------------------------------------------------*/
/** @addtogroup APP_RNG_DRIVER_FUNCTIONS Functions
* @{
*/
/**
****************************************************************************************
* @brief Initialize the APP RNG DRIVER according to the specified parameters
* in the app_rng_params_t and app_rng_evt_handler_t.
* @note If interrupt mode is set, you can use blocking mode. Conversely, if blocking mode
* is set, you can't use interrupt mode.
*
* @param[in] p_params: Pointer to app_rng_params_t parameter which contains the
* configuration information for the specified RNG module.
* @param[in] evt_handler: RNG user callback function.
*
* @return Result of initialization.
****************************************************************************************
*/
uint16_t app_rng_init(app_rng_params_t *p_params, app_rng_evt_handler_t evt_handler);
/**
****************************************************************************************
* @brief De-initialize the APP RNG DRIVER peripheral.
*
* @return Result of De-initialization.
****************************************************************************************
*/
uint16_t app_rng_deinit(void);
/**
****************************************************************************************
* @brief Generate a 32-bit random number.
*
* @param[in] p_seed: user configured seeds. the seed is valid when seed_mode member of
* rng_init_t is configured as RNG_SEED_USER. If 59-bit random number is
* selected, the seed need to provide [0~58] bit spaces. If 128-bit random
* number is selected, the seed need to provide [0~127] bit spaces.
* @param[out] p_random32bit: Pointer to generated random number variable if successful.
*
* @return Result of operation.
****************************************************************************************
*/
uint16_t app_rng_gen_sync(uint16_t *p_seed, uint32_t *p_random32bit);
/**
****************************************************************************************
* @brief Generate a 32-bit random number in interrupt mode.
*
* @param[in] p_seed: user configured seeds. the seed is valid when seed_mode member of
* rng_init_t is configured as RNG_SEED_USER. If 59-bit random number is
* selected, the seed need to provide [0~58] bit spaces. If 128-bit random
* number is selected, the seed need to provide [0~127] bit spaces.
*
* @return Result of operation.
****************************************************************************************
*/
uint16_t app_rng_gen_async(uint16_t *p_seed);
/**
****************************************************************************************
* @brief Return the RNG handle.
*
* @return Pointer to the RNG handle.
****************************************************************************************
*/
rng_handle_t *app_rng_get_handle(void);
#ifdef ENV_RTOS_USE_SEMP
/**
****************************************************************************************
* @brief [RTOS] Generate a 32-bit random number in interrupt mode.
*
* @param[in] p_seed: user configured seeds. the seed is valid when seed_mode member of
* rng_init_t is configured as RNG_SEED_USER. If 59-bit random number is
* selected, the seed need to provide [0~58] bit spaces. If 128-bit random
* number is selected, the seed need to provide [0~127] bit spaces.
*
* @return Result of operation.
****************************************************************************************
*/
uint16_t app_rng_gen_sem_sync(uint16_t *p_seed);
#endif
#endif
/** @} */
#ifdef __cplusplus
}
#endif
#endif
/** @} */
/** @} */
/** @} */
@@ -1,268 +0,0 @@
/**
****************************************************************************************
*
* @file app_rtos_cfg.h
* @author BLE Driver Team
* @brief Header file of app rtos config code.
*
****************************************************************************************
* @attention
#####Copyright (c) 2019 GOODIX
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of GOODIX nor the names of its contributors may be used
to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
****************************************************************************************
*/
/** @addtogroup PERIPHERAL Peripheral Driver
* @{
*/
/** @addtogroup APP_DRIVER APP DRIVER
* @{
*/
/** @defgroup APP_RTOS_CONFIG RTOS CONFIG
* @brief APP RTOS CONFIG
* @{
*/
#ifndef __APP_RTOS_ADAPTER_H__
#define __APP_RTOS_ADAPTER_H__
/*
* INCLUDE FILES
*****************************************************************************************
*/
#ifdef ENV_USE_FREERTOS
#include "FreeRTOS.h"
#include "semphr.h"
/** @addtogroup APP_RTOS_CONFIG_DEFINES Defines
* @{
*/
#define ENV_USE_RTOS
/** @} */
/**
* @defgroup APP_RTOS_CONFIG_TYPEDEF Typedefs
* @{
*/
/**
* @brief Semaphore type definition
*/
typedef SemaphoreHandle_t sem_t;
/**
* @brief mutex type definition
*/
typedef SemaphoreHandle_t mutex_t;
/** @} */
/** @addtogroup APP_RTOS_CONFIG_DEFINES Defines
* @{
*/
#define OS_WAIT_FOREVER portMAX_DELAY /**< Block forever until get resource */
#define SEM_WAIT_FOREVER portMAX_DELAY /**< Wait for the semaphore forever */
#define SEM_NO_WAIT (0) /**< Non-block */
#define MUTEX_WAIT_FOREVER portMAX_DELAY /**< Wait for the mutex forever */
#define MUTEX_NO_WAIT (0) /**< Non-block */
/** @} */
#else
/**
* @defgroup APP_RTOS_CONFIG_TYPEDEF Typedefs
* @{
*/
typedef void *sem_t;
typedef void *mutex_t;
/** @} */
/** @addtogroup APP_RTOS_CONFIG_DEFINES Defines
* @{
*/
#define SEM_WAIT_FOREVER (0xFFFFUL) /**< Wait for the semaphore forever. */
#define SEM_NO_WAIT (0) /**< Non-block */
#define MUTEX_WAIT_FOREVER (0xFFFFUL) /**< Wait for the mutex forever */
#define MUTEX_NO_WAIT (0) /**< Non-block */
/** @} */
#endif
/** @addtogroup APP_RTOS_CONFIG_DEFINES Defines
* @{
*/
#define APP_DRV_SEM_DECL(sem) sem_t sem /**< Define a semaphore instance */
#define APP_DRV_MUTEX_DECL(mutex) mutex_t mutex /**< Define a mutex instance */
/** @} */
#ifdef ENV_USE_RTOS
/** @addtogroup APP_RTOS_CONFIG_DEFINES Defines
* @{
*/
#define ENV_RTOS_USE_SEMP 1 /**< Enable semaphore in app driver */
// #define ENV_RTOS_USE_MUTEX 1 /**< Enable mutex in app driver */
/** @} */
/** @addtogroup APP_RTOS_CONFIG_FUNCTIONS Functions
* @{
*/
/**
****************************************************************************************
* @brief Initialize a semaphore.
*
* @param[in] sem: Pointer to a sem_t parameter which contains the address of the semaphore object.
*
* @return Result of initialization.
****************************************************************************************
*/
uint16_t app_driver_sem_init(sem_t *sem);
/**
****************************************************************************************
* @brief De-initialize a semaphore.
*
* @param[in] sem: the semaphore object.
*
* @return Result of De-initialization.
****************************************************************************************
*/
void app_driver_sem_deinit(sem_t sem);
/**
****************************************************************************************
* @brief This function will take a semaphore, if the semaphore is unavailable, the
thread shall wait for a specified time.
*
* @param[in] sem: The semaphore object.
* @param[in] time_out: The waiting time in milliseconds.
*
* @return Result of operation.
****************************************************************************************
*/
uint16_t app_driver_sem_pend(sem_t sem, uint32_t time_out);
/**
****************************************************************************************
* @brief This function will release a semaphore, if there are threads suspended on
* semaphore, it will be waked up.
*
* @param[in] sem: The semaphore object.
*
* @return Result of operation.
****************************************************************************************
*/
uint16_t app_driver_sem_post(sem_t sem);
/**
****************************************************************************************
* @brief This function will release a semaphore, it is used in interrupt service function,
* if there are threads suspended on semaphore, it will be waked up.
*
* @param[in] sem: The semaphore object.
*
* @return Result of operation.
****************************************************************************************
*/
uint16_t app_driver_sem_post_from_isr(sem_t sem);
/**
****************************************************************************************
* @brief Initialize a mutex.
*
* @param[in] mutex: Pointer to mutex_t parameter which contains the address of the mutex object.
*
* @return Result of initialization.
****************************************************************************************
*/
uint16_t app_driver_mutex_init(mutex_t *mutex);
/**
****************************************************************************************
* @brief De-initialize a mutex.
*
* @param[in] mutex: the mutex object.
*
* @return Result of De-initialization.
****************************************************************************************
*/
void app_driver_mutex_deinit(mutex_t mutex);
/**
****************************************************************************************
* @brief This function will take a mutex, if the mutex is unavailable, the thread shall
* wait for a specified time.
*
* @param[in] mutex: The mutex object.
* @param[in] time_out: The waiting time in milliseconds.
*
* @return Result of operation.
****************************************************************************************
*/
uint16_t app_driver_mutex_pend(mutex_t mutex, uint32_t time_out);
/**
****************************************************************************************
* @brief This function will release a mutex, if there are threads suspended on mutex,
* it will be waked up.
*
* @param[in] mutex: The mutex object.
*
* @return Result of operation.
****************************************************************************************
*/
uint16_t app_driver_mutex_post(mutex_t mutex);
/** @} */
#else
/** @addtogroup APP_RTOS_CONFIG_DEFINES Defines
* @{
*/
#define app_driver_sem_init(x) (0) /**< Initialize the semaphore. */
#define app_driver_sem_deinit(x) /**< Deinitialize the semphore. */
#define app_driver_sem_pend(x, y) (0) /**< Pend the semaphore. */
#define app_driver_sem_post(x) /**< Post the semaphore. */
#define app_driver_sem_post_from_isr(x) /**< Post the semaphore from interrupt. */
#define app_driver_mutex_init(x) (0) /**< Initialize the mutex. */
#define app_driver_mutex_deinit(x) /**< Deinitialize the mutex. */
#define app_driver_mutex_pend(x, y) /**< Pend the mutex. */
#define app_driver_mutex_post(x) /**< Post the mutex. */
/** @} */
#endif
#endif
/** @} */
/** @} */
/** @} */
@@ -1,448 +0,0 @@
/**
****************************************************************************************
*
* @file app_spi.h
* @author BLE Driver Team
* @brief Header file containing functions prototypes of SPI app library.
*
****************************************************************************************
* @attention
#####Copyright (c) 2019 GOODIX
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of GOODIX nor the names of its contributors may be used
to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
****************************************************************************************
*/
/** @addtogroup PERIPHERAL Peripheral Driver
* @{
*/
/** @addtogroup APP_DRIVER APP DRIVER
* @{
*/
/** @defgroup APP_SPI SPI
* @brief SPI APP module driver.
* @{
*/
#ifndef _APP_SPI_H_
#define _APP_SPI_H_
#include "gr55xx_hal.h"
#include "app_io.h"
#include "app_drv_error.h"
#include "app_rtos_cfg.h"
#ifdef __cplusplus
extern "C" {
#endif
#ifdef HAL_SPI_MODULE_ENABLED
#ifdef _APP_SPI_V2_H_
#error "NOT Support USING app_spi AND app_spi_v2 AT The Same Time !!!"
#endif
/** @addtogroup APP_SPI_DEFINE Defines
* @{
*/
#define APP_SPI_PIN_ENABLE 1 /**< SPI pin enable */
#define APP_SPI_PIN_DISABLE 0 /**< SPI pin disable */
/** @} */
/** @addtogroup APP_SPI_ENUM Enumerations
* @{
*/
/**
* @brief SPI module Enumerations definition
*/
typedef enum {
APP_SPI_ID_SLAVE, /**< SPI slave module. */
APP_SPI_ID_MASTER, /**< SPI master module. */
APP_SPI_ID_MAX, /**< Only for check parameter, not used as input parameters. */
} app_spi_id_t;
/**
* @brief SPI operating mode Enumerations definition
*/
typedef enum {
APP_SPI_TYPE_INTERRUPT, /**< Interrupt operation mode */
APP_SPI_TYPE_POLLING, /**< Polling operation mode */
APP_SPI_TYPE_DMA, /**< DMA operation mode */
APP_SPI_TYPE_MAX, /**< Only for check parameter, not used as input parameters. */
} app_spi_type_t;
/**
* @brief SPI event Enumerations definition
*/
typedef enum {
APP_SPI_EVT_ERROR, /**< Error reported by UART peripheral. */
APP_SPI_EVT_TX_CPLT, /**< Requested TX transfer completed. */
APP_SPI_EVT_RX_DATA, /**< Requested RX transfer completed. */
APP_SPI_EVT_TX_RX, /**< Requested TX/RX transfer completed. */
} app_spi_evt_type_t;
/** @} */
/** @addtogroup APP_SPI_STRUCTURES Structures
* @{
*/
/**
* @brief SPI IO Structures
*/
typedef struct {
app_io_type_t type; /**< Specifies the type of SPI IO. */
app_io_mux_t mux; /**< Specifies the Peripheral to be connected to the selected pins. */
uint32_t pin; /**< Specifies the IO pins to be configured.
This parameter can be any value of @ref GR551x_pins. */
app_io_pull_t pull; /**< Specifies the Pull-up or Pull-Down activation for the selected pins. */
uint8_t enable; /**< Enable or disable the pin. */
} app_spi_pin_t;
/**
* @brief SPI IO configuration Structures
*/
typedef struct {
app_spi_pin_t cs; /**< Set the configuration of SPI CS pin. */
app_spi_pin_t clk; /**< Set the configuration of SPI CLK pin. */
app_spi_pin_t mosi; /**< Set the configuration of SPI MOSI pin. */
app_spi_pin_t miso; /**< Set the configuration of SPI MISO pin. */
} app_spi_pin_cfg_t;
/**
* @brief SPI operate mode Enumerations definition
*/
typedef struct {
app_spi_type_t type; /**< Specifies the operation mode of SPI. */
dma_channel_t tx_dma_channel; /**< Specifies the dma channel of SPI TX. */
dma_channel_t rx_dma_channel; /**< Specifies the dma channel of SPI RX. */
} app_spi_mode_t;
/**
* @brief SPI parameters structure definition
*/
typedef struct {
app_spi_id_t id; /**< specified SPI module ID. */
app_spi_pin_cfg_t pin_cfg; /**< the pin configuration information for the specified SPI module. */
app_spi_mode_t use_mode; /**< SPI operate mode. */
spi_init_t init; /**< SPI communication parameters. */
} app_spi_params_t;
/**
* @brief SPI event structure definition
*/
typedef struct {
app_spi_evt_type_t type; /**< Type of event. */
union {
uint32_t error_code; /**< SPI Error code . */
uint16_t size; /**< SPI transmitted/received counter. */
} data; /**< SPI data. */
} app_spi_evt_t;
/**
* @brief SPI event callback definition
*/
typedef void (*app_spi_evt_handler_t)(app_spi_evt_t *p_evt);
/** @} */
/* Exported functions --------------------------------------------------------*/
/** @addtogroup APP_SPI_DRIVER_FUNCTIONS Functions
* @{
*/
/**
****************************************************************************************
* @brief Initialize the APP SPI DRIVER according to the specified parameters
* in the app_spi_params_t and app_spi_evt_handler_t.
* @note If interrupt mode is set, you can use blocking mode. Conversely, if blocking mode
* is set, you can't use interrupt mode.
*
* @param[in] p_params: Pointer to app_spi_params_t parameter which contains the
* configuration information for the specified SPI module.
* @param[in] evt_handler: SPI user callback function.
*
*
* @return Result of initialization.
****************************************************************************************
*/
uint16_t app_spi_init(app_spi_params_t *p_params, app_spi_evt_handler_t evt_handler);
/**
****************************************************************************************
* @brief De-initialize the APP SPI DRIVER peripheral.
*
* @param[in] id: De-initialize for a specific ID.
*
* @return Result of De-initialization.
****************************************************************************************
*/
uint16_t app_spi_deinit(app_spi_id_t id);
/**
****************************************************************************************
* @brief Receive in master or slave mode an amount of data in blocking mode.
*
* @param[in] id: which SPI module want to receive.
* @param[in] p_data: Pointer to data buffer
* @param[in] size: Amount of data to be sent
* @param[in] timeout: Timeout duration
*
* @return Result of operation.
****************************************************************************************
*/
uint16_t app_spi_receive_sync(app_spi_id_t id, uint8_t *p_data, uint16_t size, uint32_t timeout);
/**
****************************************************************************************
* @brief Receive in master or slave mode an amount of data in non-blocking mode with Interrupt
*
* @param[in] id: which SPI module want to receive.
* @param[in] p_data: Pointer to data buffer
* @param[in] size: Amount of data to be sent
*
* @return Result of operation.
****************************************************************************************
*/
uint16_t app_spi_receive_async(app_spi_id_t id, uint8_t *p_data, uint16_t size);
/**
****************************************************************************************
* @brief Transmits in master or slave mode an amount of data in blocking mode.
*
* @param[in] id: which SPI module want to transmit.
* @param[in] p_data: Pointer to data buffer
* @param[in] size: Amount of data to be sent
* @param[in] timeout: Timeout duration
*
* @return Result of operation.
****************************************************************************************
*/
uint16_t app_spi_transmit_sync(app_spi_id_t id, uint8_t *p_data, uint16_t size, uint32_t timeout);
/**
****************************************************************************************
* @brief Transmits in master or slave mode an amount of data in non-blocking mode with Interrupt
*
* @param[in] id: which SPI module want to transmit.
* @param[in] p_data: Pointer to data buffer
* @param[in] size: Amount of data to be sent
*
* @return Result of operation.
****************************************************************************************
*/
uint16_t app_spi_transmit_async(app_spi_id_t id, uint8_t *p_data, uint16_t size);
/**
****************************************************************************************
* @brief Transmits and receive in master or slave mode an amount of data in blocking mode.
*
* @param[in] id: which SPI module want to transmit.
* @param[in] p_tx_data: Pointer to tx data buffer
* @param[in] p_rx_data: Pointer to rx data buffer
* @param[in] size: Amount of data to be sent and receive
* @param[in] timeout: Timeout duration
*
* @return Result of operation.
****************************************************************************************
*/
uint16_t app_spi_transmit_receive_sync(app_spi_id_t id, uint8_t *p_tx_data,
uint8_t *p_rx_data, uint32_t size, uint32_t timeout);
/**
****************************************************************************************
* @brief Transmits and receive in master or slave mode an amount of data in non-blocking mode with Interrupt
*
* @param[in] id: which SPI module want to transmit.
* @param[in] p_tx_data: Pointer to tx data buffer
* @param[in] p_rx_data: Pointer to rx data buffer
* @param[in] size: Amount of data to be sent and receive
*
* @return Result of operation.
****************************************************************************************
*/
uint16_t app_spi_transmit_receive_async(app_spi_id_t id, uint8_t *p_tx_data, uint8_t *p_rx_data, uint32_t size);
/**
****************************************************************************************
* @brief Read an amount of data from EEPROM in blocking mode.
*
* @param[in] id: which SPI module want to transmit.
* @param[in] p_tx_data: Pointer to transmission data buffer
* @param[out] p_rx_data: Pointer to reception data buffer
* @param[in] tx_size: Amount of data to be sent in bytes
* @param[in] rx_size: Amount of data to be received in bytes
* @param[in] timeout: Timeout duration
*
* @return Result of operation.
****************************************************************************************
*/
uint16_t app_spi_read_eeprom_sync(app_spi_id_t id, uint8_t *p_tx_data, uint8_t *p_rx_data,
uint32_t tx_size, uint32_t rx_size, uint32_t timeout);
/**
****************************************************************************************
* @brief Read an amount of data from EEPROM in non-blocking mode with Interrupt.
*
* @param[in] id: which SPI module want to transmit.
* @param[in] p_tx_data: Pointer to transmission data buffer
* @param[out] p_rx_data: Pointer to reception data buffer
* @param[in] tx_size: Amount of data to be sent in bytes
* @param[in] rx_size: Amount of data to be received in bytes
*
* @return Result of operation.
****************************************************************************************
*/
uint16_t app_spi_read_eeprom_async(app_spi_id_t id, uint8_t *p_tx_data, uint8_t *p_rx_data,
uint32_t tx_size, uint32_t rx_size);
/**
****************************************************************************************
* @brief Transmits in master or slave mode an amount of data in non-blocking mode with DMA
*
* @param[in] id: which SPI module want to transmit.
* @param[in] p_cmd_data: Pointer to command data buffer
* @param[in] p_tx_data: Pointer to transmission data buffer
* @param[in] cmd_size: Amount of command data to be sent in bytes
* @param[in] tx_size: Amount of data to be sent in bytes
*
* @return Result of operation.
****************************************************************************************
*/
uint16_t app_spi_write_memory_async(app_spi_id_t id, uint8_t *p_cmd_data, uint8_t *p_tx_data,
uint32_t cmd_size, uint32_t tx_size);
/**
****************************************************************************************
* @brief Read an amount of data from EEPROM in non-blocking mode with DMA.
*
* @param[in] id: which SPI module want to transmit.
* @param[in] p_cmd_data: Pointer to command data buffer
* @param[out] p_rx_data: Pointer to reception data buffer
* @param[in] cmd_size: Amount of command data to be sent in bytes
* @param[in] rx_size: Amount of data to be received in bytes
*
* @return Result of operation.
****************************************************************************************
*/
uint16_t app_spi_read_memory_async(app_spi_id_t id, uint8_t *p_cmd_data, uint8_t *p_rx_data,
uint32_t cmd_size, uint32_t rx_size);
/**
****************************************************************************************
* @brief Return the SPI handle.
*
* @param[in] id: SPI Channel ID.
*
* @return Pointer to the specified ID's SPI handle.
****************************************************************************************
*/
spi_handle_t *app_spi_get_handle(app_spi_id_t id);
#ifdef ENV_RTOS_USE_SEMP
/**
****************************************************************************************
* @brief [RTOS] Receive in master or slave mode an amount of data in blocking mode.
*
* @param[in] id: which SPI module want to receive.
* @param[in] p_data: Pointer to data buffer
* @param[in] size: Amount of data to be sent
*
* @return Result of operation.
****************************************************************************************
*/
uint16_t app_spi_receive_sem_sync(app_spi_id_t id, uint8_t *p_data, uint16_t size);
/**
****************************************************************************************
* @brief [RTOS] Transmits in master or slave mode an amount of data in blocking mode.
*
* @param[in] id: which SPI module want to transmit.
* @param[in] p_data: Pointer to data buffer
* @param[in] size: Amount of data to be sent
*
* @return Result of operation.
****************************************************************************************
*/
uint16_t app_spi_transmit_sem_sync(app_spi_id_t id, uint8_t *p_data, uint16_t size);
/**
****************************************************************************************
* @brief [RTOS] Transmits and receive in master or slave mode an amount of data in blocking mode.
*
* @param[in] id: which SPI module want to transmit.
* @param[in] p_tx_data: Pointer to tx data buffer
* @param[in] p_rx_data: Pointer to rx data buffer
* @param[in] size: Amount of data to be sent and receive
*
* @return Result of operation.
****************************************************************************************
*/
uint16_t app_spi_transmit_receive_sem_sync(app_spi_id_t id, uint8_t *p_tx_data, uint8_t *p_rx_data, uint32_t size);
#endif
/**
****************************************************************************************
* @brief [High speed] Receive in master or slave mode an amount of data in blocking mode.
*
* @param[in] id: which SPI module want to receive.
* @param[in] p_data: Pointer to data buffer
* @param[in] size: Amount of data to be sent
*
* @return Result of operation.
****************************************************************************************
*/
uint16_t app_spi_receive_high_speed_sync(app_spi_id_t id, uint8_t *p_data, uint16_t size);
/**
****************************************************************************************
* @brief [High speed] Transmit in master or slave mode an amount of data in blocking mode.
*
* @param[in] id: which SPI module want to receive.
* @param[in] p_data: Pointer to data buffer
* @param[in] size: Amount of data to be sent
*
* @return Result of operation.
****************************************************************************************
*/
uint16_t app_spi_transmit_high_speed_sync(app_spi_id_t id, uint8_t *p_data, uint16_t size);
/** @} */
#endif
#ifdef __cplusplus
}
#endif
#endif
/** @} */
/** @} */
/** @} */
@@ -1,93 +0,0 @@
/**
****************************************************************************************
*
* @file app_systick.h
* @author BLE Driver Team
* @brief Header file containing functions prototypes of systick app library.
*
****************************************************************************************
* @attention
#####Copyright (c) 2019 GOODIX
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of GOODIX nor the names of its contributors may be used
to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
****************************************************************************************
*/
/** @addtogroup PERIPHERAL Peripheral Driver
* @{
*/
/** @addtogroup APP_DRIVER APP DRIVER
* @{
*/
/** @defgroup APP_SYSTICK SYSTICK
* @brief SYSTICK APP module driver.
* @{
*/
#ifndef _APP_SYSTICK_H_
#define _APP_SYSTICK_H_
/* Exported functions --------------------------------------------------------*/
/** @addtogroup APP_SYSTICK_DRIVER_FUNCTIONS Functions
* @{
*/
/**
****************************************************************************************
* @brief This function configures time base source, NVIC and Low level hardware.
*
* @note This function is called at the beginning of program after reset and before
* the clock configuration.
* The Systick configuration is based on AHB clock and the NVIC configuration
* is set to Priority group 4.
* The time base configuration is done, time base tick starts incrementing.
* In the default implementation, Systick is used as source of time base.
* The tick variable is incremented each 1ms in its ISR.
*
****************************************************************************************
*/
void app_systick_init(void);
/**
****************************************************************************************
* @brief This function de-Initializes common part of the HAL and stops the source
* of time base.
*
* @note This function is optional.
*
****************************************************************************************
*/
void app_systick_deinit(void);
/** @} */
#endif
/** @} */
/** @} */
/** @} */
@@ -1,322 +0,0 @@
/**
****************************************************************************************
*
* @file app_uart.h
* @author BLE Driver Team
* @brief Header file containing functions prototypes of UART app library.
*
****************************************************************************************
* @attention
#####Copyright (c) 2019 GOODIX
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of GOODIX nor the names of its contributors may be used
to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
****************************************************************************************
*/
/** @addtogroup PERIPHERAL Peripheral Driver
* @{
*/
/** @addtogroup APP_DRIVER APP DRIVER
* @{
*/
/** @defgroup APP_UART UART
* @brief UART APP module driver.
* @{
*/
#ifndef _APP_UART_H_
#define _APP_UART_H_
#include "gr55xx_hal.h"
#include "ring_buffer.h"
#include "app_io.h"
#ifdef ENV_USE_FREERTOS
#include "app_rtos_cfg.h"
#endif
#ifdef __cplusplus
extern "C" {
#endif
#ifdef HAL_UART_MODULE_ENABLED
/** @addtogroup APP_UART_ENUMERATIONS Enumertations
* @{
*/
/**
* @brief UART module Enumerations definition
*/
typedef enum {
APP_UART_ID_0, /**< UART module 0 */
APP_UART_ID_1, /**< UART module 1 */
APP_UART_ID_MAX, /**< Only for check parameter, not used as input parameters. */
} app_uart_id_t;
/**
* @brief UART operating mode Enumerations definition
*/
typedef enum {
APP_UART_TYPE_INTERRUPT, /**< Interrupt operation mode */
APP_UART_TYPE_POLLING, /**< Polling operation mode */
APP_UART_TYPE_DMA, /**< DMA operation mode */
APP_UART_TYPE_MAX, /**< Only for check parameter, not used as input parameters. */
} app_uart_type_t;
/**
* @brief UART event Enumerations definition
*/
typedef enum {
APP_UART_EVT_ERROR, /**< Error reported by UART peripheral. */
APP_UART_EVT_TX_CPLT, /**< Requested TX transfer completed. */
APP_UART_EVT_RX_DATA, /**< Requested RX transfer completed. */
APP_UART_EVT_ABORT_TX, /**< Requested TX abort completed. */
APP_UART_EVT_ABORT_RX, /**< Requested RX abort completed. */
} app_uart_evt_type_t;
/** @} */
/** @addtogroup APP_UART_STRUCTURES Structures
* @{
*/
/**
* @brief UART IO Structures
*/
typedef struct {
app_io_type_t type; /**< Specifies the type of UART IO. */
app_io_mux_t mux; /**< Specifies the Peripheral to be connected to the selected pins. */
uint32_t pin; /**< Specifies the IO pins to be configured.
This parameter can be any value of @ref GR551x_pins. */
app_io_pull_t pull; /**< Specifies the Pull-up or Pull-Down activation for the selected pins. */
} app_uart_pin_t;
/**
* @brief UART IO configuration Structures
*/
typedef struct {
app_uart_pin_t tx; /**< Set the configuration of UART TX pin. */
app_uart_pin_t rx; /**< Set the configuration of UART RX pin. */
app_uart_pin_t cts; /**< Set the configuration of UART CTS pin. */
app_uart_pin_t rts; /**< Set the configuration of UART RTS pin. */
} app_uart_pin_cfg_t;
/**
* @brief UART operate mode Enumerations definition
*/
typedef struct {
app_uart_type_t type; /**< Specifies the operation mode of UART. */
dma_channel_t tx_dma_channel; /**< Specifies the dma channel of UART TX. */
dma_channel_t rx_dma_channel; /**< Specifies the dma channel of UART RX. */
} app_uart_mode_t;
/**
* @brief UART parameters structure definition
*/
typedef struct {
app_uart_id_t id; /**< specified UART module ID. */
app_uart_pin_cfg_t pin_cfg; /**< the pin configuration information for the specified UART module. */
app_uart_mode_t use_mode; /**< UART operate mode. */
uart_init_t init; /**< UART communication parameters. */
} app_uart_params_t;
/**
* @brief UART event structure definition
*/
typedef struct {
app_uart_evt_type_t type; /**< Type of event. */
union {
uint32_t error_code; /**< UART Error code . */
uint16_t size; /**< UART transmitted/received counter. */
} data; /**< UART event data. */
} app_uart_evt_t;
/**
* @brief UART event callback definition
*/
typedef void (*app_uart_evt_handler_t)(app_uart_evt_t *p_evt);
/**
* @brief UART buffer structure definition
*/
typedef struct {
uint8_t *tx_buf; /**< Pointer to the TX buffer. */
uint32_t tx_buf_size; /**< Size of the TX buffer. */
} app_uart_tx_buf_t;
/** @} */
/* Exported functions --------------------------------------------------------*/
/** @addtogroup APP_UART_DRIVER_FUNCTIONS Functions
* @{
*/
/**
****************************************************************************************
* @brief Initialize the APP UART DRIVER according to the specified parameters
* in the app_uart_params_t and app_uart_evt_handler_t.
*
* @param[in] p_params: Pointer to app_uart_params_t parameter which contains the
* configuration information for the specified UART module.
* @param[in] evt_handler: UART user callback function.
* @param[in] tx_buffer: Pointer to tx send buffer.
*
* @return Result of initialization.
****************************************************************************************
*/
uint16_t app_uart_init(app_uart_params_t *p_params, app_uart_evt_handler_t evt_handler, app_uart_tx_buf_t *tx_buffer);
/**
****************************************************************************************
* @brief De-initialize the APP UART DRIVER peripheral.
*
* @param[in] id: De-initialize for a specific ID.
*
* @return Result of De-initialization.
****************************************************************************************
*/
uint16_t app_uart_deinit(app_uart_id_t id);
/**
****************************************************************************************
* @brief Send an amount of data in interrupt mode.
*
* @param[in] id: which UART module want to receive.
* @param[in] p_data: Pointer to data buffer
* @param[in] size: Amount of data to be sent
*
* @return Result of operation.
****************************************************************************************
*/
uint16_t app_uart_transmit_async(app_uart_id_t id, uint8_t *p_data, uint16_t size);
/**
****************************************************************************************
* @brief Send an amount of data in blocking mode.
*
* @param[in] id: which UART module want to receive.
* @param[in] p_data: Pointer to data buffer
* @param[in] size: Amount of data to be sent
* @param[in] timeout: Timeout duration
*
* @return Result of operation.
****************************************************************************************
*/
uint16_t app_uart_transmit_sync(app_uart_id_t id, uint8_t *p_data, uint16_t size, uint32_t timeout);
/**
****************************************************************************************
* @brief Receive an amount of data in interrupt mode.
*
* @param[in] id: which UART module want to transmit.
* @param[in] p_data: Pointer to data buffer
* @param[in] size: Amount of data to be sent
*
* @return Result of operation.
****************************************************************************************
*/
uint16_t app_uart_receive_async(app_uart_id_t id, uint8_t *p_data, uint16_t size);
/**
****************************************************************************************
* @brief Receive an amount of data in blocking mode.
*
* @param[in] id: which UART module want to transmit.
* @param[in] p_data: Pointer to data buffer
* @param[in] size: Amount of data to be sent
* @param[in] timeout: Timeout duration
*
* @return Result of operation.
****************************************************************************************
*/
uint16_t app_uart_receive_sync(app_uart_id_t id, uint8_t *p_data, uint16_t size, uint32_t timeout);
/**
****************************************************************************************
* @brief Return the UART handle.
*
* @param[in] id: UART Channel ID.
*
* @return Pointer to the specified ID's UART handle.
****************************************************************************************
*/
uart_handle_t *app_uart_get_handle(app_uart_id_t id);
/**
*****************************************************************************************
* @brief Flush all log entries from the buffer
*
* @param[in] id: UART Channel ID.
*
*****************************************************************************************
*/
void app_uart_flush(app_uart_id_t id);
#ifdef ENV_RTOS_USE_SEMP
/**
****************************************************************************************
* @brief [RTOS] Receive an amount of data in blocking mode.
*
* @param[in] id: which UART module want to transmit.
* @param[in] p_data: Pointer to data buffer
* @param[in] size: Amount of data to be sent
*
* @return Result of operation.
****************************************************************************************
*/
uint16_t app_uart_receive_sem_sync(app_uart_id_t id, uint8_t *p_data, uint16_t size);
/**
****************************************************************************************
* @brief [RTOS] Send an amount of data in blocking mode.
*
* @param[in] id: which UART module want to receive.
* @param[in] p_data: Pointer to data buffer
* @param[in] size: Amount of data to be sent
*
* @return Result of operation.
****************************************************************************************
*/
uint16_t app_uart_transmit_sem_sync(app_uart_id_t id, uint8_t *p_data, uint16_t size);
#endif
/** @} */
#endif
#ifdef __cplusplus
}
#endif
#endif
/** @} */
/** @} */
/** @} */
@@ -1,330 +0,0 @@
/**
****************************************************************************************
* @file app_dma.c
* @author BLE Driver Team
* @brief HAL APP module driver.
****************************************************************************************
* @attention
#####Copyright (c) 2019 GOODIX
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of GOODIX nor the names of its contributors may be used
to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
****************************************************************************************
*/
/*
* INCLUDE FILES
*****************************************************************************************
*/
#include <string.h>
#include <stdbool.h>
#include "app_pwr_mgmt.h"
#include "platform_sdk.h"
#include "app_dma.h"
/*
* DEFINES
*****************************************************************************************
*/
#define DMA_HANDLE_MAX 8
/*
* STRUCT DEFINE
*****************************************************************************************
*/
/**@brief App dma state types. */
typedef enum {
APP_DMA_INVALID = 0,
APP_DMA_ENABLE,
#ifdef APP_DRIVER_WAKEUP_CALL_FUN
APP_DMA_SLEEP,
#endif
} app_dma_state_t;
struct dma_env_t {
app_dma_state_t dma_state;
dma_handle_t handle;
app_dma_evt_handler_t evt_handler;
};
/*
* LOCAL FUNCTION DECLARATION
*****************************************************************************************
*/
static bool dma_prepare_for_sleep(void);
static void dma_sleep_canceled(void);
static void dma_wake_up_ind(void);
/*
* LOCAL VARIABLE DEFINITIONS
*****************************************************************************************
*/
static bool s_sleep_cb_registered_flag = false;
static struct dma_env_t s_dma_env[DMA_HANDLE_MAX];
static int16_t s_dma_pwr_id;
static const app_sleep_callbacks_t dma_sleep_cb = {
.app_prepare_for_sleep = dma_prepare_for_sleep,
.app_sleep_canceled = dma_sleep_canceled,
.app_wake_up_ind = dma_wake_up_ind,
};
/*
* LOCAL FUNCTION DEFINITIONS
*****************************************************************************************
*/
static bool dma_prepare_for_sleep(void)
{
hal_dma_state_t state;
for (uint8_t i = 0; i < DMA_HANDLE_MAX; i++) {
if (s_dma_env[i].dma_state == APP_DMA_ENABLE) {
state = hal_dma_get_state(&s_dma_env[i].handle);
if ((state != HAL_DMA_STATE_RESET) && (state != HAL_DMA_STATE_READY)) {
return false;
}
hal_dma_suspend_reg(&s_dma_env[i].handle);
#ifdef APP_DRIVER_WAKEUP_CALL_FUN
s_dma_env[i].dma_state = APP_DMA_SLEEP;
#endif
}
}
return true;
}
static void dma_sleep_canceled(void)
{
}
SECTION_RAM_CODE static void dma_wake_up_ind(void)
{
#ifndef APP_DRIVER_WAKEUP_CALL_FUN
bool find = false;
for (uint8_t i = 0; i < DMA_HANDLE_MAX; i++) {
if (s_dma_env[i].dma_state == APP_DMA_ENABLE) {
hal_dma_resume_reg(&s_dma_env[i].handle);
find = true;
}
}
if (find) {
hal_nvic_clear_pending_irq(DMA_IRQn);
hal_nvic_enable_irq(DMA_IRQn);
}
#endif
}
#ifdef APP_DRIVER_WAKEUP_CALL_FUN
void dma_wake_up(int16_t id)
{
if (id<0 || id >= DMA_HANDLE_MAX) {
return;
}
if (s_dma_env[id].dma_state == APP_DMA_SLEEP) {
hal_dma_resume_reg(&s_dma_env[id].handle);
s_dma_env[id].dma_state = APP_DMA_ENABLE;
if (!NVIC_GetEnableIRQ(DMA_IRQn)) {
hal_nvic_clear_pending_irq(DMA_IRQn);
hal_nvic_enable_irq(DMA_IRQn);
}
}
}
#endif
/*
* GLOBAL FUNCTION DEFINITIONS
****************************************************************************************
*/
void dma_tfr_callback(struct _dma_handle *hdma)
{
uint8_t i;
for (i = 0; i < DMA_HANDLE_MAX; i++) {
if ((s_dma_env[i].dma_state == APP_DMA_ENABLE) &&
(s_dma_env[i].handle.channel == hdma->channel)) {
if (s_dma_env[i].evt_handler != NULL) {
s_dma_env[i].evt_handler(APP_DMA_EVT_TFR);
}
break;
}
}
}
void dma_err_callback(struct _dma_handle * hdma)
{
uint8_t i;
for (i = 0; i < DMA_HANDLE_MAX; i++) {
if ((s_dma_env[i].dma_state == APP_DMA_ENABLE) &&
(s_dma_env[i].handle.channel == hdma->channel)) {
if (s_dma_env[i].evt_handler != NULL) {
s_dma_env[i].evt_handler(APP_DMA_EVT_ERROR);
}
break;
}
}
}
static void dma_handle_config(uint8_t *p_i, int16_t *p_id, app_dma_params_t *p_params)
{
GLOBAL_EXCEPTION_DISABLE();
for (*p_i = 0; (*p_i) < DMA_HANDLE_MAX; (*p_i)++) {
if (s_dma_env[*p_i].dma_state == APP_DMA_INVALID || \
s_dma_env[*p_i].handle.channel == p_params->channel_number) {
if (HAL_DMA_STATE_BUSY == s_dma_env[*p_i].handle.state) {
*p_i = DMA_HANDLE_MAX;
break;
} else {
*p_id = *p_i;
s_dma_env[*p_i].dma_state = APP_DMA_ENABLE;
break;
}
}
}
GLOBAL_EXCEPTION_ENABLE();
}
int16_t app_dma_init(app_dma_params_t *p_params, app_dma_evt_handler_t evt_handler)
{
uint8_t i = 0;
int16_t id = -1;
hal_status_t status = HAL_ERROR;
if (p_params != NULL) {
if (!IS_DMA_ALL_INSTANCE(p_params->channel_number)) {
return -1;
}
dma_handle_config(&i, &id, p_params);
if (i < DMA_HANDLE_MAX) {
if (s_sleep_cb_registered_flag == false) { // register sleep callback
s_sleep_cb_registered_flag = true;
s_dma_pwr_id = pwr_register_sleep_cb(&dma_sleep_cb, APP_DRIVER_DMA_WAPEUP_PRIORITY);
}
s_dma_env[i].handle.channel = p_params->channel_number;
memcpy_s(&s_dma_env[i].handle.init, sizeof(s_dma_env[i].handle.init), &p_params->init, sizeof(dma_init_t));
s_dma_env[i].handle.xfer_tfr_callback = dma_tfr_callback;
s_dma_env[i].handle.xfer_error_callback = dma_err_callback;
s_dma_env[i].handle.xfer_abort_callback = NULL;
s_dma_env[i].evt_handler = evt_handler;
hal_nvic_clear_pending_irq(DMA_IRQn);
hal_nvic_enable_irq(DMA_IRQn);
status = hal_dma_init(&s_dma_env[i].handle);
}
}
if (HAL_OK != status) {
id = -1;
}
return id;
}
uint16_t app_dma_deinit(int16_t id)
{
uint8_t i;
if ((id < 0) || (id >= DMA_HANDLE_MAX) || (s_dma_env[id].dma_state == APP_DMA_INVALID)) {
return APP_DRV_ERR_INVALID_ID;
}
GLOBAL_EXCEPTION_DISABLE();
hal_dma_deinit(&s_dma_env[id].handle);
s_dma_env[id].dma_state = APP_DMA_INVALID;
s_dma_env[id].handle.channel = (dma_channel_t)(-1);
for (i = 0; i < DMA_HANDLE_MAX; i++) {
if (s_dma_env[i].dma_state == APP_DMA_ENABLE) {
break;
}
}
if (i == DMA_HANDLE_MAX) {
pwr_unregister_sleep_cb(s_dma_pwr_id);
s_sleep_cb_registered_flag = false;
hal_nvic_disable_irq(DMA_IRQn);
}
GLOBAL_EXCEPTION_ENABLE();
return APP_DRV_SUCCESS;
}
dma_handle_t *app_dma_get_handle(int16_t id)
{
if (id < 0 || id >= DMA_HANDLE_MAX || s_dma_env[id].dma_state == APP_DMA_INVALID) {
return NULL;
}
#ifdef APP_DRIVER_WAKEUP_CALL_FUN
dma_wake_up(id);
#endif
return &s_dma_env[id].handle;
}
uint16_t app_dma_start(int16_t id, uint32_t src_address, uint32_t dst_address, uint32_t data_length)
{
hal_status_t status = HAL_ERROR;
if (id < 0 || id >= DMA_HANDLE_MAX || s_dma_env[id].dma_state == APP_DMA_INVALID) {
return APP_DRV_ERR_INVALID_PARAM;
}
#ifdef APP_DRIVER_WAKEUP_CALL_FUN
dma_wake_up(id);
#endif
status = hal_dma_start_it(&s_dma_env[id].handle, src_address, dst_address, data_length);
if (HAL_OK != status) {
return (uint16_t)status;
}
return APP_DRV_SUCCESS;
}
SECTION_RAM_CODE void DMA_IRQHandler(void)
{
#if FLASH_PROTECT_PRIORITY
platform_interrupt_protection_push();
#endif
uint8_t i;
for (i = 0; i < DMA_HANDLE_MAX; i++) {
if (s_dma_env[i].dma_state == APP_DMA_ENABLE) {
hal_dma_irq_handler(&s_dma_env[i].handle);
}
}
#if FLASH_PROTECT_PRIORITY
platform_interrupt_protection_pop();
#endif
}
@@ -1,436 +0,0 @@
/**
****************************************************************************************
* @file app_gpiote.c
* @author BLE Driver Team
* @brief HAL APP module driver.
****************************************************************************************
* @attention
#####Copyright (c) 2019 GOODIX
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of GOODIX nor the names of its contributors may be used
to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
****************************************************************************************
*/
/*
* INCLUDE FILES
*****************************************************************************************
*/
#include <string.h>
#include "app_pwr_mgmt.h"
#include "platform_sdk.h"
#include "app_gpiote.h"
/*
* DEFINES
*****************************************************************************************
*/
#define BIT_8 8
#define BIT_16 16
#define BIT_24 24
#define GPIOTE_USE_PATTERN 0x47
#define GPIOTE_USE_MAX 32
#define GPIOTE_AON_PIN_USE_MAX 8
/*
* STRUCT DEFINE
*****************************************************************************************
*/
struct gpiote_env_t {
uint8_t total_used;
app_gpiote_param_t params[GPIOTE_USE_MAX];
};
/*
* LOCAL FUNCTION DECLARATION
*****************************************************************************************
*/
static bool gpiote_prepare_for_sleep(void);
static void gpiote_sleep_canceled(void);
static void gpiote_wake_up_ind(void);
/*
* LOCAL VARIABLE DEFINITIONS
*****************************************************************************************
*/
static struct gpiote_env_t s_gpiote_env;
static bool s_sleep_cb_registered_flag = false;
static uint16_t s_gpiote_pwr_id;
static const app_sleep_callbacks_t gpiote_sleep_cb = {
.app_prepare_for_sleep = gpiote_prepare_for_sleep,
.app_sleep_canceled = gpiote_sleep_canceled,
.app_wake_up_ind = gpiote_wake_up_ind
};
static app_io_callback_t aon_cb_called_table[GPIOTE_AON_PIN_USE_MAX];
/*
* LOCAL FUNCTION DEFINITIONS
*****************************************************************************************
*/
static bool gpiote_prepare_for_sleep(void)
{
return true;
}
static void gpiote_sleep_canceled(void)
{
}
SECTION_RAM_CODE static void gpiote_wake_up_ind(void)
{
bool is_ext0_need_enable = false;
bool is_ext1_need_enable = false;
for (int idx = 0; idx < s_gpiote_env.total_used; idx++) {
if (s_gpiote_env.params[idx].type == APP_IO_TYPE_NORMAL) {
if (APP_IO_PINS_0_15 & s_gpiote_env.params[idx].pin) {
is_ext0_need_enable = true;
continue;
}
if (APP_IO_PINS_16_31 & s_gpiote_env.params[idx].pin) {
is_ext1_need_enable = true;
continue;
}
}
}
if (is_ext0_need_enable) {
hal_nvic_enable_irq(EXT0_IRQn);
}
if (is_ext1_need_enable) {
hal_nvic_enable_irq(EXT1_IRQn);
}
return;
}
static uint16_t params_check(const app_gpiote_param_t *p_params, uint8_t table_cnt)
{
if (p_params == NULL) {
return APP_DRV_ERR_POINTER_NULL;
}
if (((s_gpiote_env.total_used + table_cnt) > GPIOTE_USE_MAX) && table_cnt) {
return APP_DRV_ERR_INVALID_PARAM;
}
return APP_DRV_SUCCESS;
}
static void gpiote_wakeup_mode_config(uint8_t idx, const app_gpiote_param_t *p_params)
{
if ((p_params[idx].handle_mode == APP_IO_ENABLE_WAKEUP) && (p_params[idx].type == APP_IO_TYPE_AON)) {
switch (p_params[idx].mode) {
case APP_IO_MODE_IT_RISING:
hal_pwr_config_ext_wakeup(p_params[idx].pin, PWR_EXTWKUP_TYPE_RISING);
break;
case APP_IO_MODE_IT_FALLING:
hal_pwr_config_ext_wakeup(p_params[idx].pin, PWR_EXTWKUP_TYPE_FALLING);
break;
case APP_IO_MODE_IT_HIGH:
hal_pwr_config_ext_wakeup(p_params[idx].pin, PWR_EXTWKUP_TYPE_HIGH);
break;
case APP_IO_MODE_IT_LOW:
hal_pwr_config_ext_wakeup(p_params[idx].pin, PWR_EXTWKUP_TYPE_LOW);
break;
default:
break;
}
pwr_mgmt_wakeup_source_setup(PWR_WKUP_COND_EXT);
}
}
static uint16_t register_cb(void)
{
if (!s_sleep_cb_registered_flag) { // register sleep callback
s_gpiote_pwr_id = pwr_register_sleep_cb(&gpiote_sleep_cb, APP_DRIVER_GPIOTE_WAPEUP_PRIORITY);
if (s_gpiote_pwr_id < 0) {
return APP_DRV_ERR_INVALID_PARAM;
}
s_sleep_cb_registered_flag = true;
}
return APP_DRV_SUCCESS;
}
/*
* GLOBAL FUNCTION DEFINITIONS
****************************************************************************************
*/
uint16_t app_gpiote_init(const app_gpiote_param_t *p_params, uint8_t table_cnt)
{
static uint8_t exit_flag = 0x0;
app_io_init_t io_init;
uint16_t err_code;
err_code = params_check(p_params, table_cnt);
APP_DRV_ERR_CODE_CHECK(err_code);
for (uint8_t idx = 0; idx < table_cnt; idx++) {
exit_flag = 0x0;
for (uint8_t index = 0; index < s_gpiote_env.total_used; index ++) {
if (s_gpiote_env.params[index].pin == p_params[idx].pin && \
s_gpiote_env.params[index].type == p_params[idx].type) {
exit_flag = 0x1;
break;
}
}
io_init.pin = p_params[idx].pin;
io_init.mode = p_params[idx].mode;
io_init.pull = p_params[idx].pull;
io_init.mux = APP_IO_MUX_7;
app_io_deinit(p_params[idx].type, io_init.pin);
err_code = app_io_init(p_params[idx].type, &io_init);
APP_DRV_ERR_CODE_CHECK(err_code);
if (exit_flag) {
continue;
}
memcpy_s(&s_gpiote_env.params[s_gpiote_env.total_used],
sizeof(s_gpiote_env.params[s_gpiote_env.total_used]),
&p_params[idx], sizeof(app_gpiote_param_t));
gpiote_wakeup_mode_config(idx, p_params);
if (p_params[idx].type == APP_IO_TYPE_NORMAL) {
hal_nvic_clear_pending_irq(EXT0_IRQn);
hal_nvic_enable_irq(EXT0_IRQn);
hal_nvic_clear_pending_irq(EXT1_IRQn);
hal_nvic_enable_irq(EXT1_IRQn);
} else if (p_params[idx].type == APP_IO_TYPE_AON) {
hal_nvic_clear_pending_irq(EXT2_IRQn);
hal_nvic_enable_irq(EXT2_IRQn);
}
s_gpiote_env.total_used += 1;
}
err_code = register_cb();
APP_DRV_ERR_CODE_CHECK(err_code);
return APP_DRV_SUCCESS;
}
static void gpiote_config_wake_up_config(const app_gpiote_param_t *p_config)
{
if ((p_config->handle_mode == APP_IO_ENABLE_WAKEUP) && (p_config->type == APP_IO_TYPE_AON)) {
switch (p_config->mode) {
case APP_IO_MODE_IT_RISING:
hal_pwr_config_ext_wakeup(p_config->pin, PWR_EXTWKUP_TYPE_RISING);
break;
case APP_IO_MODE_IT_FALLING:
hal_pwr_config_ext_wakeup(p_config->pin, PWR_EXTWKUP_TYPE_FALLING);
break;
case APP_IO_MODE_IT_HIGH:
hal_pwr_config_ext_wakeup(p_config->pin, PWR_EXTWKUP_TYPE_HIGH);
break;
case APP_IO_MODE_IT_LOW:
hal_pwr_config_ext_wakeup(p_config->pin, PWR_EXTWKUP_TYPE_LOW);
break;
default:
break;
}
pwr_mgmt_wakeup_source_setup(PWR_WKUP_COND_EXT);
}
}
uint16_t app_gpiote_config(const app_gpiote_param_t *p_config)
{
uint8_t exit_flag = 0x0;
uint8_t index;
app_io_init_t io_init;
uint16_t err_code;
if (p_config == NULL) {
return APP_DRV_ERR_POINTER_NULL;
}
for (index = 0; index < s_gpiote_env.total_used; index ++) {
if (s_gpiote_env.params[index].pin == p_config->pin && \
s_gpiote_env.params[index].type == p_config->type) {
exit_flag = 0x1;
break;
}
}
if (!exit_flag || index >= GPIOTE_USE_MAX) {
return APP_DRV_ERR_INVALID_PARAM;
}
memcpy_s(&s_gpiote_env.params[index], sizeof(s_gpiote_env.params[index]),
p_config, sizeof(app_gpiote_param_t));
io_init.pin = p_config->pin;
io_init.mode = p_config->mode;
io_init.pull = p_config->pull;
io_init.mux = APP_IO_MUX_7;
app_io_deinit(p_config->type, p_config->pin);
err_code = app_io_init(p_config->type, &io_init);
APP_DRV_ERR_CODE_CHECK(err_code);
gpiote_config_wake_up_config(p_config);
if ((p_config->handle_mode == APP_IO_DISABLE_WAKEUP) && (p_config->type == APP_IO_TYPE_AON)) {
hal_pwr_disable_ext_wakeup(p_config->pin);
}
if (p_config->type == APP_IO_TYPE_NORMAL) {
hal_nvic_clear_pending_irq(EXT0_IRQn);
hal_nvic_enable_irq(EXT0_IRQn);
hal_nvic_clear_pending_irq(EXT1_IRQn);
hal_nvic_enable_irq(EXT1_IRQn);
} else if (p_config->type == APP_IO_TYPE_AON) {
hal_nvic_clear_pending_irq(EXT2_IRQn);
hal_nvic_enable_irq(EXT2_IRQn);
}
return APP_DRV_SUCCESS;
}
void app_gpiote_deinit(void)
{
for (int idx = 0; idx < s_gpiote_env.total_used; idx++) {
app_io_deinit(s_gpiote_env.params[idx].type, s_gpiote_env.params[idx].pin);
}
hal_nvic_disable_irq(EXT0_IRQn);
hal_nvic_disable_irq(EXT1_IRQn);
hal_nvic_disable_irq(EXT2_IRQn);
pwr_unregister_sleep_cb(s_gpiote_pwr_id);
s_gpiote_env.total_used = 0;
}
void hal_gpio_exti_callback(gpio_regs_t *GPIOx, uint16_t gpio_pin)
{
uint32_t io_pin = gpio_pin;
app_gpiote_evt_t gpiote_evt;
if (GPIO1 == GPIOx) {
io_pin = (uint32_t)(gpio_pin << BIT_16);
}
gpiote_evt.type = APP_IO_TYPE_NORMAL;
gpiote_evt.pin = io_pin;
gpiote_evt.ctx_type = APP_IO_CTX_INT;
for (uint8_t idx = 0; idx < s_gpiote_env.total_used; idx++) {
if ((s_gpiote_env.params[idx].type == APP_IO_TYPE_NORMAL) && (io_pin == s_gpiote_env.params[idx].pin)) {
if (s_gpiote_env.params[idx].io_evt_cb)
s_gpiote_env.params[idx].io_evt_cb(&gpiote_evt);
}
}
}
static void gpio_callback_config(uint8_t idx, uint16_t aon_gpio_pin, uint8_t *p_called_flag,
uint8_t *p_called_table_used_pos, app_gpiote_evt_t gpiote_evt)
{
if ((s_gpiote_env.params[idx].type == APP_IO_TYPE_AON) && \
(aon_gpio_pin & s_gpiote_env.params[idx].pin) && \
(s_gpiote_env.params[idx].io_evt_cb)) {
for (uint8_t i = 0; i < *p_called_table_used_pos; i++) {
if (aon_cb_called_table[i] == s_gpiote_env.params[idx].io_evt_cb) {
*p_called_flag = 1;
break;
} else {
*p_called_flag = 0;
}
}
if (*p_called_flag == 0) {
s_gpiote_env.params[idx].io_evt_cb(&gpiote_evt);
aon_cb_called_table[*p_called_table_used_pos] = s_gpiote_env.params[idx].io_evt_cb;
*p_called_table_used_pos++;
}
}
}
void hal_aon_gpio_callback(uint16_t aon_gpio_pin)
{
uint8_t called_table_used_pos = 0;
uint8_t called_flag = 0;
app_gpiote_evt_t gpiote_evt;
gpiote_evt.type = APP_IO_TYPE_AON;
gpiote_evt.pin = aon_gpio_pin;
if (pwr_mgmt_get_wakeup_flag() == WARM_BOOT) {
gpiote_evt.ctx_type = APP_IO_CTX_WAKEUP;
} else {
gpiote_evt.ctx_type = APP_IO_CTX_INT;
}
memset_s(aon_cb_called_table, sizeof(aon_cb_called_table), 0, sizeof(aon_cb_called_table));
for (uint8_t idx = 0; idx < s_gpiote_env.total_used; idx++) {
gpio_callback_config(idx, aon_gpio_pin, &called_flag,
&called_table_used_pos, gpiote_evt);
}
}
SECTION_RAM_CODE void EXT0_IRQHandler(void)
{
#if FLASH_PROTECT_PRIORITY
platform_interrupt_protection_push();
#endif
hal_gpio_exti_irq_handler(GPIO0);
#if FLASH_PROTECT_PRIORITY
platform_interrupt_protection_pop();
#endif
}
SECTION_RAM_CODE void EXT1_IRQHandler(void)
{
#if FLASH_PROTECT_PRIORITY
platform_interrupt_protection_push();
#endif
hal_gpio_exti_irq_handler(GPIO1);
#if FLASH_PROTECT_PRIORITY
platform_interrupt_protection_pop();
#endif
}
SECTION_RAM_CODE void EXT2_IRQHandler(void)
{
#if FLASH_PROTECT_PRIORITY
platform_interrupt_protection_push();
#endif
hal_aon_gpio_irq_handler();
#if FLASH_PROTECT_PRIORITY
platform_interrupt_protection_pop();
#endif
}
File diff suppressed because it is too large Load Diff
@@ -1,293 +0,0 @@
/**
****************************************************************************************
* @file app_io.c
* @author BLE Driver Team
* @brief HAL APP module driver.
****************************************************************************************
* @attention
#####Copyright (c) 2019 GOODIX
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of GOODIX nor the names of its contributors may be used
to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
****************************************************************************************
*/
/*
* INCLUDE FILES
*****************************************************************************************
*/
#include "gr55xx_hal_gpio.h"
#include "gr55xx_hal_aon_gpio.h"
#include "gr55xx_hal_msio.h"
#include "app_io.h"
#ifndef GR5515_E
/*
* DEFINES
*****************************************************************************************
*/
#define BIT_8 8
#define BIT_16 16
#define BIT_24 24
#define IO_MODE_NONE 0x00
/*
* LOCAL VARIABLE DEFINITIONS
*****************************************************************************************
*/
static const uint32_t s_io_pull[APP_IO_TYPE_MAX][APP_IO_PULL_MAX] = {
{ GPIO_NOPULL, GPIO_PULLUP, GPIO_PULLDOWN },
{ AON_GPIO_NOPULL, AON_GPIO_PULLUP, AON_GPIO_PULLDOWN },
{ MSIO_NOPULL, MSIO_PULLUP, MSIO_PULLDOWN },
};
static const uint32_t s_io_mode[APP_IO_TYPE_MAX][APP_IO_MODE_MAX] = {
{
GPIO_MODE_INPUT, GPIO_MODE_OUTPUT, GPIO_MODE_MUX, GPIO_MODE_IT_RISING,
GPIO_MODE_IT_FALLING, GPIO_MODE_IT_HIGH, GPIO_MODE_IT_LOW, IO_MODE_NONE
},
{
AON_GPIO_MODE_INPUT, AON_GPIO_MODE_OUTPUT, AON_GPIO_MODE_MUX, AON_GPIO_MODE_IT_RISING,
AON_GPIO_MODE_IT_FALLING, AON_GPIO_MODE_IT_HIGH, AON_GPIO_MODE_IT_LOW, IO_MODE_NONE
},
{
MSIO_DIRECTION_INPUT, MSIO_DIRECTION_OUTPUT, MSIO_DIRECTION_INPUT, IO_MODE_NONE,
IO_MODE_NONE, IO_MODE_NONE, IO_MODE_NONE, MSIO_DIRECTION_NONE
},
};
/*
* GLOBAL FUNCTION DEFINITIONS
****************************************************************************************
*/
uint16_t app_io_init(app_io_type_t type, app_io_init_t *p_init)
{
gpio_init_t io_config;
aon_gpio_init_t aon_io_config;
msio_init_t msio_config;
if (p_init == NULL) {
return APP_DRV_ERR_POINTER_NULL;
} else {
switch (type) {
case APP_IO_TYPE_NORMAL:
if (APP_IO_MODE_ANALOG == p_init->mode) {
return APP_DRV_ERR_INVALID_MODE;
}
io_config.mode = s_io_mode[type][p_init->mode];
io_config.pull = s_io_pull[type][p_init->pull];
io_config.mux = p_init->mux;
if (APP_IO_PINS_0_15 & p_init->pin) {
io_config.pin = (APP_IO_PINS_0_15 & p_init->pin);
hal_gpio_init(GPIO0, &io_config);
}
if (APP_IO_PINS_16_31 & p_init->pin) {
io_config.pin = (APP_IO_PINS_16_31 & p_init->pin) >> BIT_16;
hal_gpio_init(GPIO1, &io_config);
}
break;
case APP_IO_TYPE_AON:
if (APP_IO_MODE_ANALOG == p_init->mode) {
return APP_DRV_ERR_INVALID_MODE;
}
aon_io_config.mode = s_io_mode[type][p_init->mode];
aon_io_config.pull = s_io_pull[type][p_init->pull];
aon_io_config.mux = p_init->mux;
aon_io_config.pin = (APP_AON_IO_PIN_ALL & p_init->pin);
hal_aon_gpio_init(&aon_io_config);
break;
case APP_IO_TYPE_MSIO:
if (p_init->mode >= APP_IO_MODE_IT_RISING && p_init->mode <= APP_IO_MODE_IT_LOW) {
return APP_DRV_ERR_INVALID_MODE;
}
msio_config.direction = (APP_IO_MODE_ANALOG == p_init->mode) ? \
MSIO_DIRECTION_INPUT : s_io_mode[type][p_init->mode];
msio_config.mode = (APP_IO_MODE_ANALOG == p_init->mode)? MSIO_MODE_ANALOG : MSIO_MODE_DIGITAL;
msio_config.pull = s_io_pull[type][p_init->pull];
msio_config.mux = p_init->mux;
msio_config.pin = (APP_MSIO_PIN_ALL & p_init->pin);
hal_msio_init(&msio_config);
break;
default:
return APP_DRV_ERR_INVALID_TYPE;
}
}
return APP_DRV_SUCCESS;
}
uint16_t app_io_deinit(app_io_type_t type, uint32_t pin)
{
switch (type) {
case APP_IO_TYPE_NORMAL:
if (APP_IO_PINS_0_15 & pin) {
hal_gpio_deinit(GPIO0, (APP_IO_PINS_0_15 & pin));
}
if (APP_IO_PINS_16_31 & pin) {
hal_gpio_deinit(GPIO1, (APP_IO_PINS_16_31 & pin) >> BIT_16);
}
break;
case APP_IO_TYPE_AON:
hal_aon_gpio_deinit(APP_AON_IO_PIN_ALL & pin);
break;
case APP_IO_TYPE_MSIO:
hal_msio_deinit(APP_MSIO_PIN_ALL & pin);
break;
default:
return APP_DRV_ERR_INVALID_TYPE;
}
return APP_DRV_SUCCESS;
}
app_io_pin_state_t app_io_read_pin(app_io_type_t type, uint32_t pin)
{
app_io_pin_state_t pin_state = APP_IO_PIN_RESET;
gpio_pin_state_t io_pin_state = GPIO_PIN_RESET;
aon_gpio_pin_state_t aon_io_pin_state = AON_GPIO_PIN_RESET;
msio_pin_state_t msio_pin_state = MSIO_PIN_RESET;
switch (type) {
case APP_IO_TYPE_NORMAL:
if (APP_IO_PINS_0_15 & pin) {
io_pin_state = hal_gpio_read_pin(GPIO0, pin);
}
if (APP_IO_PINS_16_31 & pin) {
io_pin_state = hal_gpio_read_pin(GPIO1, pin >> BIT_16);
}
pin_state = (app_io_pin_state_t)io_pin_state;
break;
case APP_IO_TYPE_AON:
aon_io_pin_state = hal_aon_gpio_read_pin(pin);
pin_state = (app_io_pin_state_t)aon_io_pin_state;
break;
case APP_IO_TYPE_MSIO:
msio_pin_state = hal_msio_read_pin(pin);
pin_state = (app_io_pin_state_t)msio_pin_state;
break;
default:
break;
}
return pin_state;
}
uint16_t app_io_write_pin(app_io_type_t type, uint32_t pin, app_io_pin_state_t pin_state)
{
if (pin_state != APP_IO_PIN_RESET && pin_state != APP_IO_PIN_SET) {
return APP_DRV_ERR_INVALID_PARAM;
}
switch (type) {
case APP_IO_TYPE_NORMAL:
if (APP_IO_PINS_0_15 & pin) {
hal_gpio_write_pin(GPIO0, (uint16_t)(APP_IO_PINS_0_15 & pin), (gpio_pin_state_t)pin_state);
}
if (APP_IO_PINS_16_31 & pin) {
hal_gpio_write_pin(GPIO1, (uint16_t)((APP_IO_PINS_16_31 & pin) >> BIT_16), (gpio_pin_state_t)pin_state);
}
break;
case APP_IO_TYPE_AON:
hal_aon_gpio_write_pin(pin, (aon_gpio_pin_state_t)pin_state);
break;
case APP_IO_TYPE_MSIO:
hal_msio_write_pin(pin, (msio_pin_state_t)pin_state);
break;
default:
return APP_DRV_ERR_INVALID_TYPE;
}
return APP_DRV_SUCCESS;
}
uint16_t app_io_toggle_pin(app_io_type_t type, uint32_t pin)
{
switch (type) {
case APP_IO_TYPE_NORMAL:
if (APP_IO_PINS_0_15 & pin) {
hal_gpio_toggle_pin(GPIO0, (uint16_t)(APP_IO_PINS_0_15 & pin));
}
if (APP_IO_PINS_16_31 & pin) {
hal_gpio_toggle_pin(GPIO1, (uint16_t)((APP_IO_PINS_16_31 & pin) >> BIT_16));
}
break;
case APP_IO_TYPE_AON:
hal_aon_gpio_toggle_pin(pin);
break;
case APP_IO_TYPE_MSIO:
hal_msio_toggle_pin(pin);
break;
default:
return APP_DRV_ERR_INVALID_TYPE;
}
return APP_DRV_SUCCESS;
}
#else
uint16_t app_io_init(app_io_type_t type, app_io_init_t *p_init)
{
return app_io_init_sym(type, p_init);
}
uint16_t app_io_deinit(app_io_type_t type, uint32_t pin)
{
return app_io_deinit_sym(type, pin);
}
app_io_pin_state_t app_io_read_pin(app_io_type_t type, uint32_t pin)
{
return app_io_read_pin_sym(type, pin);
}
uint16_t app_io_write_pin(app_io_type_t type, uint32_t pin, app_io_pin_state_t pin_state)
{
return app_io_write_pin_sym(type, pin, pin_state);
}
uint16_t app_io_toggle_pin(app_io_type_t type, uint32_t pin)
{
return app_io_toggle_pin_sym(type, pin);
}
#endif
@@ -1,377 +0,0 @@
/**
****************************************************************************************
* @file app_pwm.c
* @author BLE Driver Team
* @brief HAL APP module driver.
****************************************************************************************
* @attention
#####Copyright (c) 2019 GOODIX
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of GOODIX nor the names of its contributors may be used
to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
****************************************************************************************
*/
/*
* INCLUDE FILES
*****************************************************************************************
*/
#include <string.h>
#include "app_io.h"
#include "app_systick.h"
#include "app_pwr_mgmt.h"
#include "app_pwm.h"
#ifdef HAL_CALENDAR_MODULE_ENABLED
/*
* STRUCT DEFINE
*****************************************************************************************
*/
/**@brief App pwm state types. */
typedef enum {
APP_PWM_INVALID = 0,
APP_PWM_ENABLE,
#ifdef APP_DRIVER_WAKEUP_CALL_FUN
APP_PWM_SLEEP,
#endif
} app_pwm_state_t;
/**@brief App pwm module state types. */
typedef enum {
APP_PWM_STOP = 0,
APP_PWM_START,
} app_pwm_module_state_t;
struct pwm_env_t {
app_pwm_pin_cfg_t pin_cfg;
app_pwm_state_t pwm_state;
app_pwm_module_state_t pwm_module_state;
pwm_handle_t handle;
};
/*
* LOCAL FUNCTION DEFINITIONS
*****************************************************************************************
*/
static bool pwm_prepare_for_sleep(void);
static void pwm_sleep_canceled(void);
static void pwm_wake_up_ind(void);
static uint16_t pwm_gpio_config(app_pwm_pin_cfg_t pin_cfg);
/*
* LOCAL VARIABLE DEFINITIONS
*****************************************************************************************
*/
struct pwm_env_t s_pwm_env[APP_PWM_ID_MAX];
static const uint32_t s_pwm_instance[APP_PWM_ID_MAX] = {PWM0_BASE, PWM1_BASE};
static bool s_sleep_cb_registered_flag = false;
static uint16_t s_pwm_pwr_id;
static const app_sleep_callbacks_t pwm_sleep_cb = {
.app_prepare_for_sleep = pwm_prepare_for_sleep,
.app_sleep_canceled = pwm_sleep_canceled,
.app_wake_up_ind = pwm_wake_up_ind
};
/*
* LOCAL FUNCTION DEFINITIONS
*****************************************************************************************
*/
static bool pwm_prepare_for_sleep(void)
{
hal_pwm_state_t state;
uint8_t i;
for (i = 0; i < APP_PWM_ID_MAX; i++) {
if (s_pwm_env[i].pwm_state == APP_PWM_ENABLE) {
state = hal_pwm_get_state(&s_pwm_env[i].handle);
if ((state != HAL_PWM_STATE_RESET) && (state != HAL_PWM_STATE_READY)) {
return false;
}
GLOBAL_EXCEPTION_DISABLE();
hal_pwm_suspend_reg(&s_pwm_env[i].handle);
GLOBAL_EXCEPTION_ENABLE();
#ifdef APP_DRIVER_WAKEUP_CALL_FUN
s_pwm_env[i].pwm_state = APP_PWM_SLEEP;
#endif
}
}
return true;
}
static void pwm_sleep_canceled(void)
{
}
SECTION_RAM_CODE static void pwm_wake_up_ind(void)
{
#ifndef APP_DRIVER_WAKEUP_CALL_FUN
uint8_t i;
for (i = 0; i < APP_PWM_ID_MAX; i++) {
if (s_pwm_env[i].pwm_state == APP_PWM_ENABLE) {
GLOBAL_EXCEPTION_DISABLE();
hal_pwm_resume_reg(&s_pwm_env[i].handle);
GLOBAL_EXCEPTION_ENABLE();
if (s_pwm_env[i].pwm_module_state == APP_PWM_START) {
hal_pwm_start(&s_pwm_env[i].handle);
}
}
}
#endif
}
#ifdef APP_DRIVER_WAKEUP_CALL_FUN
static void pwm_wake_up(app_pwm_id_t id)
{
if (s_pwm_env[id].pwm_state == APP_PWM_SLEEP) {
GLOBAL_EXCEPTION_DISABLE();
hal_pwm_resume_reg(&s_pwm_env[id].handle);
GLOBAL_EXCEPTION_ENABLE();
if (s_pwm_env[id].pwm_module_state == APP_PWM_START) {
hal_pwm_start(&s_pwm_env[id].handle);
}
}
}
#endif
static uint16_t pwm_gpio_config(app_pwm_pin_cfg_t pin_cfg)
{
app_io_init_t io_init = APP_IO_DEFAULT_CONFIG;
uint16_t err_code = APP_DRV_SUCCESS;
io_init.pull = APP_IO_PULLUP;
io_init.mode = APP_IO_MODE_MUX;
if (pin_cfg.channel_a.enable == APP_PWM_PIN_ENABLE) {
io_init.pin = pin_cfg.channel_a.pin;
io_init.mux = pin_cfg.channel_a.mux;
err_code = app_io_init(pin_cfg.channel_a.type, &io_init);
APP_DRV_ERR_CODE_CHECK(err_code);
}
if (pin_cfg.channel_b.enable == APP_PWM_PIN_ENABLE) {
io_init.pin = pin_cfg.channel_b.pin;
io_init.mux = pin_cfg.channel_b.mux;
err_code = app_io_init(pin_cfg.channel_b.type, &io_init);
APP_DRV_ERR_CODE_CHECK(err_code);
}
if (pin_cfg.channel_c.enable == APP_PWM_PIN_ENABLE) {
io_init.pin = pin_cfg.channel_c.pin;
io_init.mux = pin_cfg.channel_c.mux;
err_code = app_io_init(pin_cfg.channel_c.type, &io_init);
APP_DRV_ERR_CODE_CHECK(err_code);
}
return err_code;
}
/*
* GLOBAL FUNCTION DEFINITIONS
****************************************************************************************
*/
uint16_t app_pwm_init(app_pwm_params_t *p_params)
{
uint8_t id = p_params->id;
uint16_t app_err_code;
hal_status_t hal_err_code;
if (p_params == NULL) {
return APP_DRV_ERR_POINTER_NULL;
}
if (id >= APP_PWM_ID_MAX) {
return APP_DRV_ERR_INVALID_ID;
}
app_systick_init();
app_err_code = pwm_gpio_config(p_params->pin_cfg);
APP_DRV_ERR_CODE_CHECK(app_err_code);
s_pwm_env[id].handle.active_channel = (hal_pwm_active_channel_t)p_params->active_channel;
memcpy_s(&s_pwm_env[id].pin_cfg, sizeof (s_pwm_env[id].pin_cfg), &p_params->pin_cfg, sizeof(app_pwm_pin_cfg_t));
memcpy_s(&s_pwm_env[id].handle.init, sizeof (s_pwm_env[id].handle.init), &p_params->init, sizeof(pwm_init_t));
pwm_gpio_config(s_pwm_env[id].pin_cfg);
s_pwm_env[id].handle.p_instance = (pwm_regs_t *)s_pwm_instance[id];
hal_err_code = hal_pwm_deinit(&s_pwm_env[id].handle);
HAL_ERR_CODE_CHECK(hal_err_code);
hal_err_code = hal_pwm_init(&s_pwm_env[id].handle);
HAL_ERR_CODE_CHECK(hal_err_code);
if (!s_sleep_cb_registered_flag) {
s_sleep_cb_registered_flag = true;
s_pwm_pwr_id = pwr_register_sleep_cb(&pwm_sleep_cb, APP_DRIVER_PWM_WAPEUP_PRIORITY);
if (s_pwm_pwr_id < 0) {
return APP_DRV_ERR_INVALID_PARAM;
}
}
s_pwm_env[id].pwm_state = APP_PWM_ENABLE;
s_pwm_env[id].pwm_module_state = APP_PWM_STOP;
return APP_DRV_SUCCESS;
}
uint16_t app_pwm_deinit(app_pwm_id_t id)
{
hal_status_t err_code = HAL_ERROR;
if (id >= APP_PWM_ID_MAX) {
return APP_DRV_ERR_INVALID_ID;
}
if (s_pwm_env[id].pwm_state == APP_PWM_INVALID) {
return APP_DRV_ERR_INVALID_ID;
}
GLOBAL_EXCEPTION_DISABLE();
if (s_pwm_env[APP_PWM_ID_0].pwm_state == APP_PWM_INVALID &&
s_pwm_env[APP_PWM_ID_1].pwm_state == APP_PWM_INVALID) {
pwr_unregister_sleep_cb(s_pwm_pwr_id);
s_sleep_cb_registered_flag = false;
}
GLOBAL_EXCEPTION_ENABLE();
if (s_pwm_env[id].pin_cfg.channel_a.enable == APP_PWM_PIN_ENABLE) {
app_io_deinit(s_pwm_env[id].pin_cfg.channel_a.type, s_pwm_env[id].pin_cfg.channel_a.pin);
}
if (s_pwm_env[id].pin_cfg.channel_b.enable == APP_PWM_PIN_ENABLE) {
app_io_deinit(s_pwm_env[id].pin_cfg.channel_b.type, s_pwm_env[id].pin_cfg.channel_b.pin);
}
if (s_pwm_env[id].pin_cfg.channel_c.enable == APP_PWM_PIN_ENABLE) {
app_io_deinit(s_pwm_env[id].pin_cfg.channel_c.type, s_pwm_env[id].pin_cfg.channel_c.pin);
}
err_code = hal_pwm_deinit(&s_pwm_env[id].handle);
HAL_ERR_CODE_CHECK(err_code);
s_pwm_env[id].pwm_state = APP_PWM_INVALID;
s_pwm_env[id].pwm_module_state = APP_PWM_STOP;
return APP_DRV_SUCCESS;
}
uint16_t app_pwm_start(app_pwm_id_t id)
{
hal_status_t err_code;
if (id >= APP_PWM_ID_MAX) {
return APP_DRV_ERR_INVALID_ID;
}
#ifdef APP_DRIVER_WAKEUP_CALL_FUN
pwm_wake_up(id);
#endif
err_code = hal_pwm_start(&s_pwm_env[id].handle);
HAL_ERR_CODE_CHECK(err_code);
s_pwm_env[id].pwm_module_state = APP_PWM_START;
return APP_DRV_SUCCESS;
}
uint16_t app_pwm_stop(app_pwm_id_t id)
{
hal_status_t err_code;
if (id >= APP_PWM_ID_MAX) {
return APP_DRV_ERR_INVALID_ID;
}
#ifdef APP_DRIVER_WAKEUP_CALL_FUN
pwm_wake_up(id);
#endif
err_code = hal_pwm_stop(&s_pwm_env[id].handle);
HAL_ERR_CODE_CHECK(err_code);
s_pwm_env[id].pwm_module_state = APP_PWM_STOP;
return APP_DRV_SUCCESS;
}
uint16_t app_pwm_update_freq(app_pwm_id_t id, uint32_t freq)
{
hal_status_t err_code;
if (id >= APP_PWM_ID_MAX) {
return APP_DRV_ERR_INVALID_ID;
}
#ifdef APP_DRIVER_WAKEUP_CALL_FUN
pwm_wake_up(id);
#endif
err_code = hal_pwm_update_freq(&s_pwm_env[id].handle, freq);
HAL_ERR_CODE_CHECK(err_code);
return APP_DRV_SUCCESS;
}
uint16_t app_pwm_config_channel(app_pwm_id_t id, app_pwm_active_channel_t channel, app_pwm_channel_init_t *p_config)
{
hal_status_t err_code;
hal_pwm_active_channel_t active_channel;
pwm_channel_init_t channel_cfg;
if (id >= APP_PWM_ID_MAX) {
return APP_DRV_ERR_INVALID_ID;
}
#ifdef APP_DRIVER_WAKEUP_CALL_FUN
pwm_wake_up(id);
#endif
active_channel = (hal_pwm_active_channel_t)channel;
channel_cfg.duty = p_config->duty;
channel_cfg.drive_polarity = p_config->drive_polarity;
err_code = hal_pwm_config_channel(&s_pwm_env[id].handle, &channel_cfg, active_channel);
HAL_ERR_CODE_CHECK(err_code);
return APP_DRV_SUCCESS;
}
#endif
@@ -1,147 +0,0 @@
/**
****************************************************************************************
* @file app_pwr_mgmt.c
* @author BLE Driver Team
* @brief HAL APP module driver.
****************************************************************************************
* @attention
#####Copyright (c) 2019 GOODIX
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of GOODIX nor the names of its contributors may be used
to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
****************************************************************************************
*/
/*
* INCLUDE FILES
*****************************************************************************************
*/
#include "gr55xx_hal.h"
#include "gr55xx_pwr.h"
#include "app_pwr_mgmt.h"
/*
* STRUCT DEFINES
*****************************************************************************************
*/
struct pwr_env_t {
app_sleep_callbacks_t *pwr_sleep_cb[APP_SLEEP_CB_MAX];
wakeup_priority_t wakeup_priority[APP_SLEEP_CB_MAX];
bool is_pwr_callback_reg;
};
/*
* LOCAL VARIABLE DEFINITIONS
*****************************************************************************************
*/
struct pwr_env_t s_pwr_env;
/*
* GLOBAL FUNCTION DEFINITIONS
****************************************************************************************
*/
int16_t pwr_register_sleep_cb(const app_sleep_callbacks_t *p_cb, wakeup_priority_t wakeup_priority)
{
int16_t id = -1;
uint8_t i = 0;
if (p_cb == NULL || wakeup_priority > WAPEUP_PRIORITY_HIGH || wakeup_priority < WAPEUP_PRIORITY_LOW) {
return id;
}
GLOBAL_EXCEPTION_DISABLE();
if (!s_pwr_env.is_pwr_callback_reg) {
pwr_mgmt_dev_init(pwr_wake_up_ind);
pwr_mgmt_set_callback(pwr_enter_sleep_check, NULL);
s_pwr_env.is_pwr_callback_reg = true;
}
while ((i < APP_SLEEP_CB_MAX) && (s_pwr_env.pwr_sleep_cb[i] != NULL)) {
i++;
}
if (i < APP_SLEEP_CB_MAX) {
s_pwr_env.pwr_sleep_cb[i] = (app_sleep_callbacks_t *)p_cb;
s_pwr_env.wakeup_priority[i] = wakeup_priority;
id = i;
}
GLOBAL_EXCEPTION_ENABLE();
return id;
}
void pwr_unregister_sleep_cb(int16_t id)
{
if (id < APP_SLEEP_CB_MAX) { // Is id valid?
s_pwr_env.pwr_sleep_cb[id] = NULL;
}
}
SECTION_RAM_CODE void pwr_wake_up_ind(void)
{
uint8_t i;
app_sleep_callbacks_t *p_cb;
wakeup_priority_t priority;
for (priority = WAPEUP_PRIORITY_HIGH; priority != 0; priority--) {
for (i = 0; i < APP_SLEEP_CB_MAX; i++) {
p_cb = s_pwr_env.pwr_sleep_cb[i];
if ((p_cb != NULL) && (p_cb ->app_wake_up_ind != NULL) && (priority == s_pwr_env.wakeup_priority[i])) {
p_cb ->app_wake_up_ind();
}
}
}
}
pwr_mgmt_dev_state_t pwr_enter_sleep_check(void)
{
int16_t i;
pwr_mgmt_dev_state_t allow_entering_sleep = DEVICE_IDLE;
app_sleep_callbacks_t *p_cb;
// 1. Inquiry Adapters
for (i = APP_SLEEP_CB_MAX - 1; i >= 0; i--) {
p_cb = s_pwr_env.pwr_sleep_cb[i];
if ((p_cb != NULL) && (p_cb->app_prepare_for_sleep != NULL)) {
if (!p_cb->app_prepare_for_sleep()) {
allow_entering_sleep = DEVICE_BUSY;
break;
}
}
}
// 2. If an Adapter rejected sleep, resume any Adapters that have already accepted it.
if (allow_entering_sleep == DEVICE_BUSY) {
i++;
while (i < APP_SLEEP_CB_MAX) {
p_cb = s_pwr_env.pwr_sleep_cb[i];
if ((p_cb != NULL) && (p_cb->app_sleep_canceled != NULL)) {
p_cb->app_sleep_canceled();
}
i++;
}
}
return allow_entering_sleep;
}
File diff suppressed because it is too large Load Diff
@@ -1,418 +0,0 @@
/**
****************************************************************************************
* @file app_rng.c
* @author BLE Driver Team
* @brief HAL APP module driver.
****************************************************************************************
* @attention
#####Copyright (c) 2019 GOODIX
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of GOODIX nor the names of its contributors may be used
to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
****************************************************************************************
*/
/*
* INCLUDE FILES
*****************************************************************************************
*/
#include "string.h"
#include "platform_sdk.h"
#include "app_pwr_mgmt.h"
#include "app_systick.h"
#include "app_rng.h"
#ifdef HAL_RNG_MODULE_ENABLED
/*
* DEFINES
*****************************************************************************************
*/
#ifdef ENV_RTOS_USE_MUTEX
#define APP_RNG_DRV_SYNC_MUTEX_LOCK app_driver_mutex_pend(s_rng_env.mutex_sync, MUTEX_WAIT_FOREVER)
#define APP_RNG_DRV_SYNC_MUTEX_UNLOCK app_driver_mutex_post(s_rng_env.mutex_sync)
#define APP_RNG_DRV_ASYNC_MUTEX_LOCK app_driver_mutex_pend(s_rng_env.mutex_async, MUTEX_WAIT_FOREVER)
#define APP_RNG_DRV_ASYNC_MUTEX_UNLOCK app_driver_mutex_post(s_rng_env.mutex_async)
#endif
/*
* STRUCT DEFINE
*****************************************************************************************
*/
/**@brief App rng state types. */
typedef enum {
APP_RNG_INVALID = 0,
APP_RNG_ENABLE,
#ifdef APP_DRIVER_WAKEUP_CALL_FUN
APP_RNG_SLEEP,
#endif
} app_rng_state_t;
struct rng_env_t {
app_rng_evt_handler_t evt_handler;
rng_handle_t handle;
app_rng_type_t ues_type;
app_rng_state_t rng_state;
#ifdef ENV_RTOS_USE_SEMP
APP_DRV_SEM_DECL(sem_rx);
#endif
#ifdef ENV_RTOS_USE_MUTEX
APP_DRV_MUTEX_DECL(mutex_sync);
APP_DRV_MUTEX_DECL(mutex_async);
#endif
};
/*
* LOCAL FUNCTION DECLARATION
*****************************************************************************************
*/
static bool rng_prepare_for_sleep(void);
static void rng_sleep_canceled(void);
static void rng_wake_up_ind(void);
/*
* LOCAL VARIABLE DEFINITIONS
*****************************************************************************************
*/
struct rng_env_t s_rng_env = {
.evt_handler = NULL,
#ifdef ENV_RTOS_USE_SEMP
.sem_rx = NULL,
#endif
#ifdef ENV_RTOS_USE_MUTEX
.mutex_sync = NULL,
.mutex_async = NULL,
#endif
};
static bool s_sleep_cb_registered_flag = false;
static int16_t s_rng_pwr_id;
const static app_sleep_callbacks_t rng_sleep_cb = {
.app_prepare_for_sleep = rng_prepare_for_sleep,
.app_sleep_canceled = rng_sleep_canceled,
.app_wake_up_ind = rng_wake_up_ind
};
/*
* LOCAL FUNCTION DEFINITIONS
*****************************************************************************************
*/
static bool rng_prepare_for_sleep(void)
{
hal_rng_state_t state;
if (s_rng_env.rng_state == APP_RNG_ENABLE) {
state = hal_rng_get_state(&s_rng_env.handle);
if ((state != HAL_RNG_STATE_READY) && (state != HAL_RNG_STATE_RESET)) {
return false;
}
GLOBAL_EXCEPTION_DISABLE();
hal_rng_suspend_reg(&s_rng_env.handle);
GLOBAL_EXCEPTION_ENABLE();
#ifdef APP_DRIVER_WAKEUP_CALL_FUN
s_rng_env.rng_state = APP_RNG_SLEEP;
#endif
}
return true;
}
static void rng_sleep_canceled(void)
{
}
SECTION_RAM_CODE static void rng_wake_up_ind(void)
{
#ifndef APP_DRIVER_WAKEUP_CALL_FUN
if (s_rng_env.rng_state == APP_RNG_ENABLE) {
GLOBAL_EXCEPTION_DISABLE();
hal_rng_resume_reg(&s_rng_env.handle);
GLOBAL_EXCEPTION_ENABLE();
if (s_rng_env.ues_type == APP_RNG_TYPE_INTERRUPT) {
hal_nvic_clear_pending_irq(RNG_IRQn);
hal_nvic_enable_irq(RNG_IRQn);
}
}
#endif
}
#ifdef APP_DRIVER_WAKEUP_CALL_FUN
static void rng_wake_up(void)
{
if (s_rng_env.rng_state == APP_RNG_SLEEP) {
GLOBAL_EXCEPTION_DISABLE();
hal_rng_resume_reg(&s_rng_env.handle);
GLOBAL_EXCEPTION_ENABLE();
if (s_rng_env.ues_type == APP_RNG_TYPE_INTERRUPT) {
hal_nvic_clear_pending_irq(RNG_IRQn);
hal_nvic_enable_irq(RNG_IRQn);
}
s_rng_env.rng_state = APP_RNG_ENABLE;
}
}
#endif
static void app_rng_event_call(rng_handle_t *p_rng, app_rng_evt_type_t evt_type, uint32_t random32bit)
{
app_rng_evt_t rng_evt = {APP_RNG_EVT_ERROR, 0x0};
if (p_rng->p_instance == RNG) {
rng_evt.type = evt_type;
rng_evt.random_data = random32bit;
}
#ifdef ENV_RTOS_USE_SEMP
app_driver_sem_post_from_isr(s_rng_env.sem_rx);
#endif
if (s_rng_env.evt_handler != NULL) {
s_rng_env.evt_handler(&rng_evt);
}
}
/*
* GLOBAL FUNCTION DEFINITIONS
****************************************************************************************
*/
uint16_t app_rng_init(app_rng_params_t *p_params, app_rng_evt_handler_t evt_handler)
{
hal_status_t hal_err_code = HAL_OK;
uint16_t app_err_code = APP_DRV_SUCCESS;
if (p_params == NULL) {
return APP_DRV_ERR_POINTER_NULL;
}
#ifdef ENV_RTOS_USE_SEMP
if (s_rng_env.sem_rx == NULL) {
app_err_code = app_driver_sem_init(&s_rng_env.sem_rx);
APP_DRV_ERR_CODE_CHECK(app_err_code);
}
#endif
#ifdef ENV_RTOS_USE_MUTEX
if (s_rng_env.mutex_async == NULL) {
app_err_code = app_driver_mutex_init(&s_rng_env.mutex_async);
APP_DRV_ERR_CODE_CHECK(app_err_code);
}
if (s_rng_env.mutex_sync == NULL) {
app_err_code = app_driver_mutex_init(&s_rng_env.mutex_sync);
APP_DRV_ERR_CODE_CHECK(app_err_code);
}
#endif
app_systick_init();
if (p_params->use_type == APP_RNG_TYPE_INTERRUPT) {
hal_nvic_clear_pending_irq(RNG_IRQn);
hal_nvic_enable_irq(RNG_IRQn);
}
s_rng_env.ues_type = p_params->use_type;
s_rng_env.evt_handler = evt_handler;
memcpy_s(&s_rng_env.handle.init, sizeof (s_rng_env.handle.init), &p_params->init, sizeof(rng_init_t));
s_rng_env.handle.p_instance = RNG;
hal_err_code = hal_rng_deinit(&s_rng_env.handle);
APP_DRV_ERR_CODE_CHECK(hal_err_code);
hal_err_code = hal_rng_init(&s_rng_env.handle);
APP_DRV_ERR_CODE_CHECK(hal_err_code);
if (s_sleep_cb_registered_flag == false) { // register sleep callback
s_sleep_cb_registered_flag = true;
s_rng_pwr_id = pwr_register_sleep_cb(&rng_sleep_cb, APP_DRIVER_RNG_WAPEUP_PRIORITY);
if (s_rng_pwr_id < 0) {
return APP_DRV_ERR_INVALID_PARAM;
}
}
s_rng_env.rng_state = APP_RNG_ENABLE;
return app_err_code;
}
uint16_t app_rng_deinit(void)
{
hal_status_t hal_err_code;
if (s_rng_env.rng_state == APP_RNG_INVALID) {
return APP_DRV_ERR_INVALID_ID;
}
#ifdef ENV_RTOS_USE_SEMP
if (s_rng_env.sem_rx != NULL) {
app_driver_sem_deinit(s_rng_env.sem_rx);
s_rng_env.sem_rx = NULL;
}
#endif
#ifdef ENV_RTOS_USE_MUTEX
if (s_rng_env.mutex_sync != NULL) {
app_driver_mutex_deinit(s_rng_env.mutex_sync);
s_rng_env.mutex_sync = NULL;
}
if (s_rng_env.mutex_async != NULL) {
app_driver_mutex_deinit(s_rng_env.mutex_async);
s_rng_env.mutex_async = NULL;
}
#endif
hal_nvic_disable_irq(RNG_IRQn);
s_rng_env.rng_state = APP_RNG_INVALID;
GLOBAL_EXCEPTION_DISABLE();
pwr_unregister_sleep_cb(s_rng_pwr_id);
s_sleep_cb_registered_flag = false;
GLOBAL_EXCEPTION_ENABLE();
app_systick_deinit();
hal_err_code = hal_rng_deinit(&s_rng_env.handle);
HAL_ERR_CODE_CHECK(hal_err_code);
return APP_DRV_SUCCESS;
}
uint16_t app_rng_gen_sync(uint16_t *p_seed, uint32_t *p_random32bit)
{
hal_status_t err_code;
if (s_rng_env.rng_state == APP_RNG_INVALID ||
p_seed == NULL ||
p_random32bit == NULL) {
return APP_DRV_ERR_INVALID_PARAM;
}
#ifdef APP_DRIVER_WAKEUP_CALL_FUN
rng_wake_up();
#endif
err_code = hal_rng_generate_random_number(&s_rng_env.handle, p_seed, p_random32bit);
if (err_code != HAL_OK) {
return (uint16_t)err_code;
}
return APP_DRV_SUCCESS;
}
#ifdef ENV_RTOS_USE_SEMP
uint16_t app_rng_gen_sem_sync(uint16_t *p_seed)
{
hal_status_t err_code;
#ifdef ENV_RTOS_USE_MUTEX
APP_RNG_DRV_ASYNC_MUTEX_LOCK;
#endif
if (s_rng_env.rng_state == APP_RNG_INVALID ||
s_rng_env.ues_type == APP_RNG_TYPE_POLLING ||
p_seed == NULL) {
#ifdef ENV_RTOS_USE_MUTEX
APP_RNG_DRV_ASYNC_MUTEX_UNLOCK;
#endif
return APP_DRV_ERR_INVALID_PARAM;
}
#ifdef APP_DRIVER_WAKEUP_CALL_FUN
rng_wake_up();
#endif
err_code = hal_rng_generate_random_number_it(&s_rng_env.handle, p_seed);
if (err_code != HAL_OK) {
#ifdef ENV_RTOS_USE_MUTEX
APP_RNG_DRV_ASYNC_MUTEX_UNLOCK;
#endif
return (uint16_t)err_code;
}
app_driver_sem_pend(s_rng_env.sem_rx, OS_WAIT_FOREVER);
#ifdef ENV_RTOS_USE_MUTEX
APP_RNG_DRV_ASYNC_MUTEX_UNLOCK;
#endif
return APP_DRV_SUCCESS;
}
#endif
uint16_t app_rng_gen_async(uint16_t *p_seed)
{
hal_status_t err_code;
if (s_rng_env.rng_state == APP_RNG_INVALID ||
s_rng_env.ues_type == APP_RNG_TYPE_POLLING ||
p_seed == NULL) {
return APP_DRV_ERR_INVALID_PARAM;
}
#ifdef APP_DRIVER_WAKEUP_CALL_FUN
rng_wake_up();
#endif
err_code = hal_rng_generate_random_number_it(&s_rng_env.handle, p_seed);
if (err_code != HAL_OK) {
return (uint16_t)err_code;
}
return APP_DRV_SUCCESS;
}
rng_handle_t *app_rng_get_handle(void)
{
if (s_rng_env.rng_state == APP_RNG_INVALID) {
return NULL;
}
#ifdef APP_DRIVER_WAKEUP_CALL_FUN
rng_wake_up();
#endif
return &s_rng_env.handle;
}
void hal_rng_ready_data_callback(rng_handle_t *p_rng, uint32_t random32bit)
{
app_rng_event_call(p_rng, APP_RNG_EVT_DONE, random32bit);
}
SECTION_RAM_CODE void RNG_IRQHandler(void)
{
#if FLASH_PROTECT_PRIORITY
platform_interrupt_protection_push();
#endif
hal_rng_irq_handler(&s_rng_env.handle);
#if FLASH_PROTECT_PRIORITY
platform_interrupt_protection_pop();
#endif
}
#endif
@@ -1,214 +0,0 @@
/**
****************************************************************************************
* @file app_rtos_adapter.c
* @author BLE Driver Team
* @brief HAL APP module driver.
****************************************************************************************
* @attention
#####Copyright (c) 2019 GOODIX
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of GOODIX nor the names of its contributors may be used
to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
****************************************************************************************
*/
/*
* INCLUDE FILES
*****************************************************************************************
*/
#include <stdio.h>
#include <string.h>
#include "app_drv_error.h"
#include "app_rtos_cfg.h"
#ifdef ENV_USE_FREERTOS
#include "FreeRTOS.h"
#include "semphr.h"
uint16_t app_driver_sem_init(sem_t *sem)
{
SemaphoreHandle_t *xSemaphore = (SemaphoreHandle_t *)sem;
if (sem == NULL) {
return APP_DRV_ERR_INVALID_PARAM;
}
*xSemaphore = xSemaphoreCreateBinary();
if (*xSemaphore == NULL) {
return APP_DRV_ERR_POINTER_NULL;
}
return APP_DRV_SUCCESS;
}
void app_driver_sem_deinit(sem_t sem)
{
vSemaphoreDelete(sem);
}
uint16_t app_driver_sem_pend(sem_t sem, uint32_t time_out)
{
BaseType_t ret = pdTRUE;
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
SemaphoreHandle_t xSemaphore = (SemaphoreHandle_t)sem;
TickType_t xTicks = portMAX_DELAY;
if (sem == NULL) {
return APP_DRV_ERR_INVALID_PARAM;
}
if (time_out != portMAX_DELAY) {
xTicks = pdMS_TO_TICKS(time_out);
}
if (__get_IPSR()) {
ret = xSemaphoreTakeFromISR(xSemaphore, &xHigherPriorityTaskWoken);
if (xHigherPriorityTaskWoken != pdFALSE) {
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
}
} else {
ret = xSemaphoreTake(xSemaphore, xTicks);
}
if (ret != pdTRUE) {
return APP_DRV_ERR_TIMEOUT;
}
return APP_DRV_SUCCESS;
}
uint16_t app_driver_sem_post(sem_t sem)
{
BaseType_t ret = pdTRUE;
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
SemaphoreHandle_t xSemaphore = (SemaphoreHandle_t)sem;
if (sem == NULL) {
return APP_DRV_ERR_INVALID_PARAM;
}
if (__get_IPSR()) {
ret = xSemaphoreGiveFromISR(xSemaphore, &xHigherPriorityTaskWoken);
if (xHigherPriorityTaskWoken != pdFALSE) {
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
}
} else {
ret = xSemaphoreGive(xSemaphore);
}
if (ret != pdTRUE) {
return APP_DRV_ERR_INVALID_PARAM;
}
return APP_DRV_SUCCESS;
}
uint16_t app_driver_sem_post_from_isr(sem_t sem)
{
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
BaseType_t ret = pdTRUE;
SemaphoreHandle_t xSemaphore = (SemaphoreHandle_t)sem;
if (sem == NULL) {
return APP_DRV_ERR_INVALID_PARAM;
}
ret = xSemaphoreGiveFromISR(xSemaphore, &xHigherPriorityTaskWoken);
if (xHigherPriorityTaskWoken != pdFALSE) {
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
}
if (ret != pdTRUE) {
return APP_DRV_ERR_INVALID_PARAM;
}
return APP_DRV_SUCCESS;
}
uint16_t app_driver_mutex_init(mutex_t *mutex)
{
SemaphoreHandle_t *xMutex = (SemaphoreHandle_t *)(mutex);
if (mutex == NULL) {
return APP_DRV_ERR_INVALID_PARAM;
}
*xMutex = xSemaphoreCreateMutex();
if (*xMutex == NULL) {
return APP_DRV_ERR_POINTER_NULL;
}
return APP_DRV_SUCCESS;
}
void app_driver_mutex_deinit(mutex_t mutex)
{
vSemaphoreDelete(mutex);
}
uint16_t app_driver_mutex_pend(mutex_t mutex, uint32_t time_out)
{
SemaphoreHandle_t xMutex = (SemaphoreHandle_t)mutex;
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
BaseType_t ret = pdTRUE;
TickType_t xTicks = portMAX_DELAY;
if (mutex == NULL) {
return APP_DRV_ERR_INVALID_PARAM;
}
if (time_out != portMAX_DELAY) {
xTicks = pdMS_TO_TICKS(time_out);
}
if (__get_IPSR()) {
ret = xSemaphoreTakeFromISR(xMutex, &xHigherPriorityTaskWoken);
if (xHigherPriorityTaskWoken != pdFALSE) {
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
}
} else {
ret = xSemaphoreTake(xMutex, xTicks);
}
if (ret != pdTRUE) {
return APP_DRV_ERR_TIMEOUT;
}
return APP_DRV_SUCCESS;
}
uint16_t app_driver_mutex_post(mutex_t mutex)
{
BaseType_t ret = pdTRUE;
SemaphoreHandle_t xMutex = (SemaphoreHandle_t)mutex;
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
if (mutex == NULL) {
return APP_DRV_ERR_INVALID_PARAM;
}
if (__get_IPSR()) {
ret = xSemaphoreGiveFromISR(xMutex, &xHigherPriorityTaskWoken);
if (xHigherPriorityTaskWoken != pdFALSE) {
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
}
} else {
ret = xSemaphoreGive(xMutex);
}
if (ret != pdTRUE) {
return APP_DRV_ERR_INVALID_PARAM;
}
return APP_DRV_SUCCESS;
}
#endif
File diff suppressed because it is too large Load Diff
@@ -1,114 +0,0 @@
/**
****************************************************************************************
* @file app_systick.c
* @author BLE Driver Team
* @brief HAL APP module driver.
****************************************************************************************
* @attention
#####Copyright (c) 2019 GOODIX
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of GOODIX nor the names of its contributors may be used
to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
****************************************************************************************
*/
/*
* INCLUDE FILES
*****************************************************************************************
*/
#include <stdbool.h>
#include "gr55xx_hal.h"
#include "app_pwr_mgmt.h"
#include "app_systick.h"
/*
* DEFINES
*****************************************************************************************
*/
#define SYSTICK_USE_PATTERN 0x47
/*
* LOCAL FUNCTION DECLARATION
*****************************************************************************************
*/
static bool systick_prepare_for_sleep(void);
static void systick_sleep_canceled(void);
static void systick_wake_up_ind(void);
/*
* LOCAL VARIABLE DEFINITIONS
*****************************************************************************************
*/
static uint8_t s_systick_use_flag = 0;
static bool s_sleep_cb_registered_flag = false;
static const app_sleep_callbacks_t systick_sleep_cb = {
.app_prepare_for_sleep = systick_prepare_for_sleep,
.app_sleep_canceled = systick_sleep_canceled,
.app_wake_up_ind = systick_wake_up_ind
};
static bool systick_prepare_for_sleep(void)
{
return true;
}
static void systick_sleep_canceled(void)
{
}
/*
* LOCAL FUNCTION DEFINITIONS
*****************************************************************************************
*/
SECTION_RAM_CODE static void systick_wake_up_ind(void)
{
if (s_systick_use_flag != SYSTICK_USE_PATTERN) {
return;
}
hal_init();
}
/*
* GLOBAL FUNCTION DEFINITIONS
****************************************************************************************
*/
void app_systick_init(void)
{
s_systick_use_flag = SYSTICK_USE_PATTERN;
if (s_sleep_cb_registered_flag == false) { // register sleep callback
if (!(SysTick->CTRL & SysTick_CTRL_ENABLE_Msk)) {
hal_init();
}
s_sleep_cb_registered_flag = true;
pwr_register_sleep_cb(&systick_sleep_cb, APP_DRIVER_SYSTICK_WAPEUP_PRIORITY);
}
}
void app_systick_deinit(void)
{
}
File diff suppressed because it is too large Load Diff
@@ -1,21 +0,0 @@
/*
* Copyright (c) 2021 GOODIX.
* Licensed 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.
*/
#ifndef __BOARD_CONFIG_H__
#define __BOARD_CONFIG_H__
#include "custom_config.h"
#endif
@@ -1,620 +0,0 @@
/**
****************************************************************************************
* @file gr551x_spi_flash.c
* @author BLE Driver Team
* @brief HAL APP module driver.
****************************************************************************************
* @attention
#####Copyright (c) 2019 GOODIX
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of GOODIX nor the names of its contributors may be used
to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
****************************************************************************************
*/
/*
* INCLUDE FILES
*****************************************************************************************
*/
#include <string.h>
#include "gr55xx_hal.h"
#include "gr551x_spi_flash.h"
/*
* DEFINES
*****************************************************************************************
*/
#define BIT_0 0
#define BIT_8 8
#define BIT_16 16
#define BIT_24 24
#define SPI_SPEED_1M (1000000)
#define SPI_SPEED_2M (2000000)
#define SPI_SPEED_4M (4000000)
#define SPI_SPEED_8M (8000000)
#define SPI_SPEED_16M (16000000)
#define SPI_SPEED_32M (32000000)
#define DEFAULT_QSPI_SPEED (SPI_SPEED_8M)
#define DEFAULT_QSPI_IO_CONFIG { { APP_IO_TYPE_NORMAL, APP_IO_MUX_2, APP_IO_PIN_15}, \
{ APP_IO_TYPE_NORMAL, APP_IO_MUX_2, APP_IO_PIN_9 }, \
{ APP_IO_TYPE_NORMAL, APP_IO_MUX_2, APP_IO_PIN_8 }, \
{ APP_IO_TYPE_NORMAL, APP_IO_MUX_2, APP_IO_PIN_14}, \
{ APP_IO_TYPE_NORMAL, APP_IO_MUX_2, APP_IO_PIN_13}, \
{ APP_IO_TYPE_NORMAL, APP_IO_MUX_2, APP_IO_PIN_12} }
#define DEFAULT_QSPI_MODE_CONFIG { APP_QSPI_TYPE_DMA, DMA_Channel7 }
#define DEFAULT_QSPI_CONFIG { (SystemCoreClock / DEFAULT_QSPI_SPEED), QSPI_CLOCK_MODE_3, 0}
#define DEFAULT_QSPI_PARAM_CONFIG { APP_QSPI_ID_1, DEFAULT_QSPI_IO_CONFIG, \
DEFAULT_QSPI_MODE_CONFIG, DEFAULT_QSPI_CONFIG}
#define DEFAULT_SPIM_SPEED (SPI_SPEED_8M)
#define DEFAULT_SPIM_IO_CONFIG { {APP_IO_TYPE_NORMAL, APP_IO_MUX_7, APP_IO_PIN_15}, \
{APP_IO_TYPE_NORMAL, APP_IO_MUX_1, APP_IO_PIN_12}, \
{APP_IO_TYPE_NORMAL, APP_IO_MUX_1, APP_IO_PIN_13}, \
{APP_IO_TYPE_NORMAL, APP_IO_MUX_1, APP_IO_PIN_14} }
#define DEFAULT_SPIM_MODE_CONFIG {APP_SPI_TYPE_DMA, DMA_Channel5, DMA_Channel6}
#define DEFAULT_SPIM_CONFIG {SPI_DATASIZE_8BIT, SPI_POLARITY_LOW, \
SPI_PHASE_1EDGE, (SystemCoreClock / DEFAULT_SPIM_SPEED), \
SPI_TIMODE_DISABLE, SPI_SLAVE_SELECT_0}
#define DEFAULT_SPIM_PARAM_CONFIG {APP_SPI_ID_MASTER, DEFAULT_SPIM_IO_CONFIG, \
DEFAULT_SPIM_MODE_CONFIG, DEFAULT_SPIM_CONFIG}
#define MS_5000 5000
/*
* LOCAL VARIABLE DEFINITIONS
*****************************************************************************************
*/
static volatile qspi_control_t g_qspi_ctl;
static dma_handle_t g_dma_handle;
static spi_handle_t g_spim_handle;
static qspi_handle_t g_qspi_handle;
static flash_init_t g_flash_init;
/*
* LOCAL FUNCTION DEFINITIONS
*****************************************************************************************
*/
static void spi_app_qspi_callback(app_qspi_evt_t *p_evt)
{
if (p_evt->type == APP_QSPI_EVT_TX_CPLT) {
g_qspi_ctl.qspi_tmt_done = 1;
}
if (p_evt->type == APP_QSPI_EVT_RX_DATA) {
g_qspi_ctl.qspi_rcv_done = 1;
}
if (p_evt->type == APP_QSPI_EVT_ERROR) {
g_qspi_ctl.qspi_tmt_done = 1;
g_qspi_ctl.qspi_rcv_done = 1;
}
}
void spi_app_spim_callback(app_spi_evt_t *p_evt)
{
if (p_evt->type == APP_SPI_EVT_TX_CPLT) {
g_qspi_ctl.spi_tmt_done = 1;
}
if (p_evt->type == APP_SPI_EVT_RX_DATA) {
g_qspi_ctl.spi_rcv_done = 1;
}
if (p_evt->type == APP_SPI_EVT_ERROR) {
g_qspi_ctl.spi_tmt_done = 1;
g_qspi_ctl.spi_rcv_done = 1;
}
}
static void spi_flash_write_enable(void)
{
uint8_t control_frame[1] = {SPI_FLASH_CMD_WREN};
if (FLASH_SPIM_ID == g_flash_init.spi_type) {
g_qspi_ctl.spi_tmt_done = 0;
app_spi_transmit_async(g_qspi_ctl.spi_id, control_frame, sizeof(control_frame));
while (g_qspi_ctl.spi_tmt_done == 0);
} else {
g_qspi_ctl.qspi_tmt_done = 0;
app_qspi_transmit_async(g_qspi_ctl.qspi_id, control_frame, sizeof(control_frame));
while (g_qspi_ctl.qspi_tmt_done == 0);
}
return;
}
static uint8_t spi_flash_read_status(void)
{
uint8_t status = 0;
if (FLASH_SPIM_ID == g_flash_init.spi_type) {
uint8_t control_frame[1] = {SPI_FLASH_CMD_RDSR};
g_qspi_ctl.spi_rcv_done = 0;
app_spi_read_memory_async(g_qspi_ctl.spi_id, control_frame, (uint8_t*)&status, sizeof(control_frame), 1);
while (g_qspi_ctl.spi_rcv_done == 0);
} else {
qspi_command_t command = {
.instruction = SPI_FLASH_CMD_RDSR,
.address = 0,
.instruction_size = QSPI_INSTSIZE_08_BITS,
.address_size = QSPI_ADDRSIZE_00_BITS,
.data_size = QSPI_DATASIZE_08_BITS,
.dummy_cycles = 0,
.instruction_address_mode = QSPI_INST_ADDR_ALL_IN_SPI,
.data_mode = QSPI_DATA_MODE_SPI,
.length = 1,
};
g_qspi_ctl.qspi_rcv_done = 0;
app_qspi_command_receive_async(g_qspi_ctl.qspi_id, &command, (uint8_t*)&status);
while (g_qspi_ctl.qspi_rcv_done == 0);
}
return status;
}
static uint32_t spi_flash_device_size(void)
{
uint32_t flash_size = 0;
if (FLASH_SPIM_ID == g_flash_init.spi_type) {
uint8_t data[ITEM_5] = {0};
uint8_t control_frame[ITEM_5] = {SPI_FLASH_CMD_SFUD, 0, 0, 0x34, DUMMY_BYTE};
g_qspi_ctl.spi_rcv_done = 0;
app_spi_read_memory_async(g_qspi_ctl.spi_id, control_frame, data, sizeof(control_frame), sizeof(data));
while (g_qspi_ctl.spi_rcv_done == 0);
if (data[ITEM_0] != 0 && data[ITEM_3] < 0xFF) {
flash_size = ((data[ITEM_3] << BIT_24) + (data[ITEM_2] << BIT_16) +
(data[ITEM_1] << BIT_8) + (data[ITEM_0] << BIT_0) + 1) / BIT_8;
}
} else {
uint8_t data[ITEM_4] = {0};
qspi_command_t command = {
.instruction = SPI_FLASH_CMD_SFUD, // SPI_FLASH_CMD_SFUD //SPI_FLASH_CMD_RDSR
.address = 0x000034,
.instruction_size = QSPI_INSTSIZE_08_BITS,
.address_size = QSPI_ADDRSIZE_24_BITS,
.data_size = QSPI_DATASIZE_08_BITS,
.dummy_cycles = 8,
.instruction_address_mode = QSPI_INST_ADDR_ALL_IN_SPI,
.data_mode = QSPI_DATA_MODE_SPI,
.length = sizeof(data),
};
g_qspi_ctl.qspi_rcv_done = 0;
app_qspi_command_receive_async(g_qspi_ctl.qspi_id, &command, data);
while (g_qspi_ctl.qspi_rcv_done == 0);
if (data[ITEM_0] != 0 && data[ITEM_3] < 0xFF) {
flash_size = ((data[ITEM_3] << BIT_24) + (data[ITEM_2] << BIT_16) +
(data[ITEM_1] << BIT_8) + (data[ITEM_0] << BIT_0) + 1) / BIT_8;
}
}
return flash_size;
}
static uint32_t spim_flash_write(uint32_t address, uint8_t *buffer, uint32_t nbytes)
{
uint8_t control_frame[ITEM_4] = {0};
control_frame[ITEM_0] = SPI_FLASH_CMD_PP;
control_frame[ITEM_1] = (address >> BIT_16) & 0xFF;
control_frame[ITEM_2] = (address >> BIT_8) & 0xFF;
control_frame[ITEM_3] = address & 0xFF;
g_qspi_ctl.spi_tmt_done = 0;
app_spi_write_memory_async(g_qspi_ctl.spi_id, control_frame, buffer, sizeof(control_frame), nbytes);
while (g_qspi_ctl.spi_tmt_done == 0);
return nbytes;
}
static uint32_t qspi_flash_write(uint32_t address, uint8_t *buffer, uint32_t nbytes)
{
qspi_command_t command = {
.instruction = SPI_FLASH_CMD_PP,
.address = address,
.instruction_size = QSPI_INSTSIZE_08_BITS,
.address_size = QSPI_ADDRSIZE_24_BITS,
.data_size = QSPI_DATASIZE_08_BITS,
.dummy_cycles = 0,
.instruction_address_mode = QSPI_INST_ADDR_ALL_IN_SPI,
.data_mode = QSPI_DATA_MODE_SPI,
.length = nbytes,
};
g_qspi_ctl.qspi_tmt_done = 0;
app_qspi_command_transmit_async(g_qspi_ctl.qspi_id, &command, buffer);
while (g_qspi_ctl.qspi_tmt_done == 0);
return nbytes;
}
static uint32_t spim_flash_read(uint32_t address, uint8_t *buffer, uint32_t nbytes)
{
uint8_t control_frame[ITEM_4] = {0};
control_frame[ITEM_0] = SPI_FLASH_CMD_READ;
control_frame[ITEM_1] = (address >> BIT_16) & 0xFF;
control_frame[ITEM_2] = (address >> BIT_8) & 0xFF;
control_frame[ITEM_3] = address & 0xFF;
g_qspi_ctl.spi_rcv_done = 0;
app_spi_read_memory_async(g_qspi_ctl.spi_id, control_frame, buffer, sizeof(control_frame), nbytes);
while (g_qspi_ctl.spi_rcv_done == 0);
return nbytes;
}
static uint32_t qspi_flash_read(uint32_t address, uint8_t *buffer, uint32_t nbytes)
{
qspi_command_t command = {
.instruction = SPI_FLASH_CMD_READ,
.address = address,
.instruction_size = QSPI_INSTSIZE_08_BITS,
.address_size = QSPI_ADDRSIZE_24_BITS,
.data_size = QSPI_DATASIZE_08_BITS,
.dummy_cycles = 0,
.instruction_address_mode = QSPI_INST_ADDR_ALL_IN_SPI,
.data_mode = QSPI_DATA_MODE_SPI,
.length = nbytes,
};
g_qspi_ctl.qspi_rcv_done = 0;
app_qspi_command_receive_async(g_qspi_ctl.qspi_id, &command, buffer);
while (g_qspi_ctl.qspi_rcv_done == 0);
return nbytes;
}
bool spim_flash_sector_erase(uint32_t address)
{
uint8_t control_frame[4] = {0};
control_frame[ITEM_0] = SPI_FLASH_CMD_SE;
control_frame[ITEM_1] = (address >> BIT_16) & 0xFF;
control_frame[ITEM_2] = (address >> BIT_8) & 0xFF;
control_frame[ITEM_3] = address & 0xFF;
g_qspi_ctl.spi_tmt_done = 0;
app_spi_transmit_async(g_qspi_ctl.spi_id, control_frame, sizeof(control_frame));
while (g_qspi_ctl.spi_tmt_done == 0);
return true;
}
bool qspi_flash_sector_erase(uint32_t address)
{
uint8_t control_frame[4] = {0};
control_frame[ITEM_0] = SPI_FLASH_CMD_SE;
control_frame[ITEM_1] = (address >> BIT_16) & 0xFF;
control_frame[ITEM_2] = (address >> BIT_8) & 0xFF;
control_frame[ITEM_3] = address & 0xFF;
g_qspi_ctl.qspi_tmt_done = 0;
app_qspi_transmit_async(g_qspi_ctl.qspi_id, control_frame, sizeof(control_frame));
while (g_qspi_ctl.qspi_tmt_done == 0);
return true;
}
uint32_t FLASH_SPIM_ID_init(flash_init_t *p_flash_init)
{
app_spi_params_t spim_params = DEFAULT_SPIM_PARAM_CONFIG;
spim_params.pin_cfg.cs.type = p_flash_init->flash_io.spi_cs.gpio;
spim_params.pin_cfg.cs.pin = p_flash_init->flash_io.spi_cs.pin;
spim_params.pin_cfg.cs.mux = p_flash_init->flash_io.spi_cs.mux;
spim_params.pin_cfg.cs.pull = APP_IO_NOPULL;
spim_params.pin_cfg.cs.enable = APP_SPI_PIN_ENABLE;
spim_params.pin_cfg.clk.type = p_flash_init->flash_io.spi_clk.gpio;
spim_params.pin_cfg.clk.pin = p_flash_init->flash_io.spi_clk.pin;
spim_params.pin_cfg.clk.mux = p_flash_init->flash_io.spi_clk.mux;
spim_params.pin_cfg.clk.pull = APP_IO_NOPULL;
spim_params.pin_cfg.clk.enable = APP_SPI_PIN_ENABLE;
spim_params.pin_cfg.mosi.type = p_flash_init->flash_io.spi_io0.qspi_io0.gpio;
spim_params.pin_cfg.mosi.pin = p_flash_init->flash_io.spi_io0.qspi_io0.pin;
spim_params.pin_cfg.mosi.mux = p_flash_init->flash_io.spi_io0.qspi_io0.mux;
spim_params.pin_cfg.mosi.pull = APP_IO_NOPULL;
spim_params.pin_cfg.mosi.enable = APP_SPI_PIN_ENABLE;
spim_params.pin_cfg.miso.type = p_flash_init->flash_io.spi_io1.qspi_io1.gpio;
spim_params.pin_cfg.miso.pin = p_flash_init->flash_io.spi_io1.qspi_io1.pin;
spim_params.pin_cfg.miso.mux = p_flash_init->flash_io.spi_io1.qspi_io1.mux;
spim_params.pin_cfg.miso.pull = APP_IO_NOPULL;
spim_params.pin_cfg.miso.enable = APP_SPI_PIN_ENABLE;
g_qspi_ctl.spi_id = APP_SPI_ID_MASTER;
app_spi_deinit(g_qspi_ctl.spi_id);
if (app_spi_init(&spim_params, spi_app_spim_callback)) {
return;
}
}
uint32_t FLASH_SPIM_ID0_ID1_init(flash_init_t *p_flash_init, app_qspi_params_t *qspi_params)
{
if (FLASH_QSPI_ID0 == p_flash_init->spi_type) {
g_qspi_ctl.qspi_id = APP_QSPI_ID_0;
} else {
g_qspi_ctl.qspi_id = APP_QSPI_ID_1;
}
qspi_params->id = g_qspi_ctl.qspi_id;
qspi_params->pin_cfg.cs.type = p_flash_init->flash_io.spi_cs.gpio;
qspi_params->pin_cfg.cs.pin = p_flash_init->flash_io.spi_cs.pin;
qspi_params->pin_cfg.cs.mux = p_flash_init->flash_io.spi_cs.mux;
qspi_params->pin_cfg.cs.pull = APP_IO_NOPULL;
qspi_params->pin_cfg.cs.enable = APP_SPI_PIN_ENABLE;
qspi_params->pin_cfg.clk.type = p_flash_init->flash_io.spi_clk.gpio;
qspi_params->pin_cfg.clk.pin = p_flash_init->flash_io.spi_clk.pin;
qspi_params->pin_cfg.clk.mux = p_flash_init->flash_io.spi_clk.mux;
qspi_params->pin_cfg.clk.pull = APP_IO_NOPULL;
qspi_params->pin_cfg.clk.enable = APP_SPI_PIN_ENABLE;
qspi_params->pin_cfg.io_0.type = p_flash_init->flash_io.spi_io0.qspi_io0.gpio;
qspi_params->pin_cfg.io_0.pin = p_flash_init->flash_io.spi_io0.qspi_io0.pin;
qspi_params->pin_cfg.io_0.mux = p_flash_init->flash_io.spi_io0.qspi_io0.mux;
qspi_params->pin_cfg.io_0.pull = APP_IO_NOPULL;
qspi_params->pin_cfg.io_0.enable = APP_SPI_PIN_ENABLE;
qspi_params->pin_cfg.io_1.type = p_flash_init->flash_io.spi_io1.qspi_io1.gpio;
qspi_params->pin_cfg.io_1.pin = p_flash_init->flash_io.spi_io1.qspi_io1.pin;
qspi_params->pin_cfg.io_1.mux = p_flash_init->flash_io.spi_io1.qspi_io1.mux;
qspi_params->pin_cfg.io_1.pull = APP_IO_NOPULL;
qspi_params->pin_cfg.io_1.enable = APP_SPI_PIN_ENABLE;
qspi_params->pin_cfg.io_2.type = p_flash_init->flash_io.qspi_io2.gpio;
qspi_params->pin_cfg.io_2.pin = p_flash_init->flash_io.qspi_io2.pin;
qspi_params->pin_cfg.io_2.mux = p_flash_init->flash_io.qspi_io2.mux;
qspi_params->pin_cfg.io_2.pull = APP_IO_NOPULL;
qspi_params->pin_cfg.io_2.enable = APP_SPI_PIN_ENABLE;
qspi_params->pin_cfg.io_3.type = p_flash_init->flash_io.qspi_io3.gpio;
qspi_params->pin_cfg.io_3.pin = p_flash_init->flash_io.qspi_io3.pin;
qspi_params->pin_cfg.io_3.mux = p_flash_init->flash_io.qspi_io3.mux;
qspi_params->pin_cfg.io_3.pull = APP_IO_NOPULL;
qspi_params->pin_cfg.io_3.enable = APP_SPI_PIN_ENABLE;
}
uint32_t IO_init(app_qspi_params_t qspi_params)
{
if (app_qspi_init(&qspi_params, spi_app_qspi_callback)) {
return false;
}
// set qspi hold/wp pin to high
app_io_init_t io_init = APP_IO_DEFAULT_CONFIG;
io_init.mode = APP_IO_MODE_OUT_PUT;
io_init.pull = APP_IO_PULLUP;
io_init.pin = qspi_params.pin_cfg.io_2.pin;
io_init.mux = APP_IO_MUX_7;
if (app_io_init(qspi_params.pin_cfg.io_2.type, &io_init)) {
return false;
}
io_init.mode = APP_IO_MODE_OUT_PUT;
io_init.pull = APP_IO_PULLUP;
io_init.pin = qspi_params.pin_cfg.io_3.pin;
io_init.mux = APP_IO_MUX_7;
if (app_io_init(qspi_params.pin_cfg.io_3.type, &io_init)) {
return false;
}
if (app_io_write_pin(qspi_params.pin_cfg.io_2.type, qspi_params.pin_cfg.io_2.pin, APP_IO_PIN_SET)) {
return false;
}
if (app_io_write_pin(qspi_params.pin_cfg.io_3.type, qspi_params.pin_cfg.io_3.pin, APP_IO_PIN_SET)) {
return false;
}
}
/*
* GLOBAL FUNCTION DEFINITIONS
****************************************************************************************
*/
bool spi_flash_init(flash_init_t *p_flash_init)
{
memcpy_s(&g_flash_init, sizeof (g_flash_init), p_flash_init, sizeof(flash_init_t));
if (FLASH_SPIM_ID == p_flash_init->spi_type) {
FLASH_SPIM_ID_init(p_flash_init);
} else if ((FLASH_QSPI_ID0 == p_flash_init->spi_type) || (FLASH_QSPI_ID1 == p_flash_init->spi_type)) {
app_qspi_params_t qspi_params = DEFAULT_QSPI_PARAM_CONFIG;
FLASH_SPIM_ID0_ID1_init(p_flash_init, &qspi_params);
app_qspi_deinit(g_qspi_ctl.qspi_id);
IO_init(qspi_params);
}
return true;
}
uint32_t spi_flash_write(uint32_t address, uint8_t *buffer, uint32_t nbytes)
{
uint32_t page_ofs, write_size, write_cont = nbytes;
hal_status_t status = HAL_OK;
while (write_cont) {
page_ofs = address & 0xFF;
write_size = EXFLASH_SIZE_PAGE_BYTES - page_ofs;
if (write_cont < write_size) {
write_size = write_cont;
write_cont = 0;
} else {
write_cont -= write_size;
}
spi_flash_write_enable();
if (FLASH_SPIM_ID == g_flash_init.spi_type) {
spim_flash_write(address, buffer, write_size);
} else {
qspi_flash_write(address, buffer, write_size);
}
while (spi_flash_read_status() & 0x1);
address += write_size;
buffer += write_size;
}
return ((status == HAL_OK) ? nbytes : 0);
}
uint32_t spi_flash_read(uint32_t address, uint8_t *buffer, uint32_t nbytes)
{
uint32_t count = 0;
if (FLASH_SPIM_ID == g_flash_init.spi_type) {
count = spim_flash_read(address, buffer, nbytes);
} else {
count = qspi_flash_read(address, buffer, nbytes);
}
return count;
}
bool spi_flash_sector_erase(uint32_t address, uint32_t size)
{
bool status = true;
uint32_t erase_addr = address;
uint32_t sector_ofs, erase_size, erase_cont = size;
while (erase_cont) {
sector_ofs = erase_addr & 0xFFF;
erase_size = EXFLASH_SIZE_SECTOR_BYTES - sector_ofs;
if (erase_cont < erase_size) {
erase_size = erase_cont;
erase_cont = 0;
} else {
erase_cont -= erase_size;
}
spi_flash_write_enable();
if (FLASH_SPIM_ID == g_flash_init.spi_type) {
status = spim_flash_sector_erase(erase_addr);
} else {
status = qspi_flash_sector_erase(erase_addr);
}
while (spi_flash_read_status() & 0x1);
erase_addr += erase_size;
}
return status;
}
bool spi_flash_chip_erase(void)
{
hal_status_t status = HAL_OK;
uint8_t control_frame[1] = {SPI_FLASH_CMD_CE};
spi_flash_write_enable();
if (FLASH_SPIM_ID == g_flash_init.spi_type) {
g_qspi_ctl.spi_tmt_done = 0;
app_spi_transmit_async(g_qspi_ctl.spi_id, control_frame, sizeof(control_frame));
while (g_qspi_ctl.spi_tmt_done == 0);
} else {
g_qspi_ctl.qspi_tmt_done = 0;
app_qspi_transmit_async(g_qspi_ctl.qspi_id, control_frame, sizeof(control_frame));
while (g_qspi_ctl.qspi_tmt_done == 0);
}
while (spi_flash_read_status() & 0x1);
return ((status == HAL_OK) ? true : false);
}
void spi_flash_chip_reset(void)
{
uint8_t control_frame[1] = {SPI_FLASH_CMD_RSTEN};
if (FLASH_SPIM_ID == g_flash_init.spi_type) {
g_qspi_ctl.spi_tmt_done = 0;
app_spi_transmit_async(g_qspi_ctl.spi_id, control_frame, sizeof(control_frame));
while (g_qspi_ctl.spi_tmt_done == 0);
} else {
hal_qspi_transmit(&g_qspi_handle, control_frame, sizeof(control_frame), MS_5000);
}
control_frame[0] = SPI_FLASH_CMD_RST;
if (FLASH_SPIM_ID == g_flash_init.spi_type) {
g_qspi_ctl.spi_tmt_done = 0;
app_spi_transmit_async(g_qspi_ctl.spi_id, control_frame, sizeof(control_frame));
while (g_qspi_ctl.spi_tmt_done == 0);
} else {
hal_qspi_transmit(&g_qspi_handle, control_frame, sizeof(control_frame), MS_5000);
}
return;
}
uint32_t spi_flash_device_id(void)
{
uint8_t data[3] = {0};
if (FLASH_SPIM_ID == g_flash_init.spi_type) {
uint8_t control_frame[1] = {SPI_FLASH_CMD_RDID};
g_qspi_ctl.spi_rcv_done = 0;
app_spi_read_memory_async(g_qspi_ctl.spi_id, control_frame, data, sizeof(control_frame), sizeof(data));
while (g_qspi_ctl.spi_rcv_done == 0);
} else {
qspi_command_t command = {
.instruction = SPI_FLASH_CMD_RDID,
.address = 0,
.instruction_size = QSPI_INSTSIZE_08_BITS,
.address_size = QSPI_ADDRSIZE_00_BITS,
.data_size = QSPI_DATASIZE_08_BITS,
.dummy_cycles = 0,
.instruction_address_mode = QSPI_INST_ADDR_ALL_IN_SPI,
.data_mode = QSPI_DATA_MODE_SPI,
.length = 3,
};
g_qspi_ctl.qspi_rcv_done = 0;
app_qspi_command_receive_async(g_qspi_ctl.qspi_id, &command, data);
while (g_qspi_ctl.qspi_rcv_done == 0);
}
return (((uint32_t)data[ITEM_0] << BIT_16) + ((uint32_t)data[ITEM_1] << BIT_8) + data[ITEM_2]);
}
void spi_flash_device_info(uint32_t *id, uint32_t *size)
{
if (id == NULL || size == NULL) {
return;
}
*id = spi_flash_device_id();
*size = spi_flash_device_size();
return;
}
@@ -1,273 +0,0 @@
/**
****************************************************************************************
* @file gr551x_spi_flash.h
* @author BLE Driver Team
* @brief Header file containing functions prototypes of spi flash library.
****************************************************************************************
* @attention
#####Copyright (c) 2019 GOODIX
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of GOODIX nor the names of its contributors may be used
to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
****************************************************************************************
*/
#ifndef __GR551X_SPI_FLASH_H__
#define __GR551X_SPI_FLASH_H__
#include <stdbool.h>
#include "gr55xx_hal.h"
#include "app_io.h"
#include "app_qspi.h"
#include "app_spi.h"
#ifdef __cplusplus
extern "C" {
#endif
/** @addtogroup Flash operation instruction macro definition
* @{
*/
#define SPI_FLASH_CMD_WRSR 0x01
#define SPI_FLASH_CMD_WRSR1 0x31
#define SPI_FLASH_CMD_RDSR 0x05
#define SPI_FLASH_CMD_WREN 0x06
#define SPI_FLASH_CMD_WRDI 0x04
#define SPI_FLASH_CMD_READ 0x03
#define SPI_FLASH_CMD_FREAD 0x0B
#define SPI_FLASH_CMD_DOFR 0x3B
#define SPI_FLASH_CMD_DIOFR 0xBB
#define SPI_FLASH_CMD_QOFR 0x6B
#define SPI_FLASH_CMD_QIOFR 0xEB
#define SPI_FLASH_CMD_READ_RESET 0xFF
#define SPI_FLASH_CMD_PP 0x02
#define SPI_FLASH_CMD_SE 0x20
#define SPI_FLASH_CMD_BE_32 0x52
#define SPI_FLASH_CMD_BE_64 0xD8
#define SPI_FLASH_CMD_CE 0xC7
#define SPI_FLASH_CMD_PES 0x75
#define SPI_FLASH_CMD_PER 0x7A
#define SPI_FLASH_CMD_RDI 0xAB
#define SPI_FLASH_CMD_REMS 0x90
#define SPI_FLASH_CMD_RDID 0x9F
#define SPI_FLASH_CMD_RSTEN 0x66
#define SPI_FLASH_CMD_RST 0x99
#define SPI_FLASH_CMD_DP 0xB9
#define SPI_FLASH_CMD_RDP 0xAB
#define SPI_FLASH_CMD_SFUD 0x5A
#define DUMMY_BYTE 0xFF
#define SPI_FLASH_PAGE_SIZE 0x00100
#define SPI_FLASH_SECTOR_SIZE 0x01000
#define SPI_FLASH_BLOCK_SIZE 0x10000
#define SPI_FLASH_ADDRESS_MAX 0xFFFFF
/** @} */
/** @addtogroup Flash hardware interface default parameters
* @{
*/
#define DEFAULT_SPIM_GROUP0 {{APP_IO_TYPE_NORMAL, APP_IO_PIN_6, APP_IO_MUX_7}, \
{APP_IO_TYPE_NORMAL, APP_IO_PIN_3, APP_IO_MUX_2}, \
{APP_IO_TYPE_NORMAL, APP_IO_PIN_4, APP_IO_MUX_2}, \
{APP_IO_TYPE_NORMAL, APP_IO_PIN_5, APP_IO_MUX_2}}
#define DEFAULT_SPIM_GROUP1 {{APP_IO_TYPE_NORMAL, APP_IO_PIN_4, APP_IO_MUX_7}, \
{APP_IO_TYPE_NORMAL, APP_IO_PIN_7, APP_IO_MUX_4}, \
{APP_IO_TYPE_NORMAL, APP_IO_PIN_6, APP_IO_MUX_4}, \
{APP_IO_TYPE_NORMAL, APP_IO_PIN_5, APP_IO_MUX_4}}
#define DEFAULT_SPIM_GROUP2 {{APP_IO_TYPE_NORMAL, APP_IO_PIN_15, APP_IO_MUX_7}, \
{APP_IO_TYPE_NORMAL, APP_IO_PIN_12, APP_IO_MUX_1}, \
{APP_IO_TYPE_NORMAL, APP_IO_PIN_13, APP_IO_MUX_1}, \
{APP_IO_TYPE_NORMAL, APP_IO_PIN_14, APP_IO_MUX_1}}
#define DEFAULT_SPIM_GROUP3 {{APP_IO_TYPE_NORMAL, APP_IO_PIN_17, APP_IO_MUX_7}, \
{APP_IO_TYPE_NORMAL, APP_IO_PIN_24, APP_IO_MUX_0}, \
{APP_IO_TYPE_NORMAL, APP_IO_PIN_25, APP_IO_MUX_0}, \
{APP_IO_TYPE_NORMAL, APP_IO_PIN_16, APP_IO_MUX_0}}
/** @} */
/**
* @addtogroup Spi Flash IO configuration Structures
* @{
*/
typedef enum {
FLASH_SPIM_ID, /**< SPI master module. */
FLASH_QSPI_ID0, /**< QSPI master module 0. */
FLASH_QSPI_ID1, /**< QSPI master module 1. */
FLASH_SPI_ID_MAX, /**< Only for check parameter, not used as input parameters. */
} spi_type_t;
typedef struct _spi_io {
app_io_type_t gpio;
uint32_t pin;
app_io_mux_t mux;
} spi_io_t;
typedef struct _flash_io {
spi_io_t spi_cs;
spi_io_t spi_clk;
union {
spi_io_t spim_mosi;
spi_io_t qspi_io0;
} spi_io0;
union {
spi_io_t spim_miso;
spi_io_t qspi_io1;
} spi_io1;
spi_io_t qspi_io2;
spi_io_t qspi_io3;
} flash_io_t;
typedef struct _flash_init {
spi_type_t spi_type;
flash_io_t flash_io;
} flash_init_t;
typedef struct flash_control {
uint8_t qspi_tmt_done;
uint8_t qspi_rcv_done;
app_qspi_id_t qspi_id;
uint8_t spi_tmt_done;
uint8_t spi_rcv_done;
app_spi_id_t spi_id;
} qspi_control_t;
/** @} */
/* Exported functions --------------------------------------------------------*/
/** @addtogroup HAL_SPI_FLASH_DRIVER_FUNCTIONS Functions
* @{
*/
/**
****************************************************************************************
* @brief Initialize the SPI FLASH DRIVER according to the specified parameters
* in the spi_flash_io_t.
*
* @param[in] p_params: Pointer to spi_flash_io_t parameter.
*
****************************************************************************************
*/
bool spi_flash_init(flash_init_t *p_flash_init);
/**
*******************************************************************************
* @brief Write flash Memory.
*
* @param[in] address: start address in flash to write data to.
* @param[in,out] buffer: buffer of data to write.
* @param[in] nbytes: number of bytes to write.
*
* @return number of bytes written
*******************************************************************************
*/
uint32_t spi_flash_write(uint32_t address, uint8_t *buffer, uint32_t nbytes);
/**
*******************************************************************************
* @brief Read flash Memory.
*
* @param[in] address: start address in flash to read data.
* @param[in,out] buffer: buffer to read data to.
* @param[in] nbytes: number of bytes to read.
*
* @return number of bytes read
*******************************************************************************
*/
uint32_t spi_flash_read(uint32_t address, uint8_t *buffer, uint32_t nbytes);
/**
*******************************************************************************
* @brief Erase flash region.
*
* @note All sectors that have address in range of [addr, addr+len]
* will be erased. If addr is not sector aligned, preceding data
* on the sector that addr belongs to will also be erased.
* If (addr + size) is not sector aligned, the whole sector
* will also be erased.
*
* @param[in] address: start address in flash to write data to.
* @param[in] size: number of bytes to write.
*
* @retval true: If successful.
* @retval false: If failure.
*******************************************************************************
*/
bool spi_flash_sector_erase(uint32_t address, uint32_t size);
/**
*******************************************************************************
* @brief Erase flash chip.
*
* @retval true: If successful.
* @retval false: If failure.
*******************************************************************************
*/
bool spi_flash_chip_erase(void);
/**
*******************************************************************************
* @brief Reset flash chip.
*
*******************************************************************************
*/
void spi_flash_chip_reset(void);
/**
*******************************************************************************
* @brief Get flash chip id.
*
* @retval Flash chip id.
*******************************************************************************
*/
uint32_t spi_flash_device_id(void);
/**
*******************************************************************************
* @brief Get Flash information.
*
* @param[in,out] id: Pointer to flash id.
* @param[in,out] size: Pointer to flash size.
*
*******************************************************************************
*/
void spi_flash_device_info(uint32_t *id, uint32_t *size);
/** @} */
#ifdef __cplusplus
}
#endif
#endif // __GR551X_SPI_FLASH_H__
View File
View File
View File
View File
View File
View File
View File
View File
View File
View File
View File
View File
View File
View File
View File

Some files were not shown because too many files have changed in this diff Show More