123 lines
		
	
	
		
			4.2 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
		
		
			
		
	
	
			123 lines
		
	
	
		
			4.2 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
|  | /****************************************************************************
 | ||
|  | 
 | ||
|  | Copyright(c) 2019 by Aerospace C.Power (Chongqing) Microelectronics. ALL RIGHTS RESERVED. | ||
|  | 
 | ||
|  | This Information is proprietary to Aerospace C.Power (Chongqing) Microelectronics and MAY NOT | ||
|  | be copied by any method or incorporated into another program without | ||
|  | the express written consent of Aerospace C.Power. This Information or any portion | ||
|  | thereof remains the property of Aerospace C.Power. The Information contained herein | ||
|  | is believed to be accurate and Aerospace C.Power assumes no responsibility or | ||
|  | liability for its use in any way and conveys no license or title under | ||
|  | any patent or copyright and makes no representation or warranty that this | ||
|  | Information is free from patent or copyright infringement. | ||
|  | 
 | ||
|  | ****************************************************************************/ | ||
|  | 
 | ||
|  | #ifndef _APP_GPIO_H_
 | ||
|  | #define _APP_GPIO_H_
 | ||
|  | 
 | ||
|  | #include "app_flash.h"
 | ||
|  | #include "app_types.h"
 | ||
|  | 
 | ||
|  | #ifdef __cplusplus
 | ||
|  |    extern "C" { | ||
|  | #endif
 | ||
|  | 
 | ||
|  | 
 | ||
|  | /* Max items count of all GPIO */ | ||
|  | #define APP_IO_PIN_MAX_NUM                    12
 | ||
|  | #define APP_GPIO_STATE_MAX_VALUE              1
 | ||
|  | #define APP_PWM_DUTY_CYCLE_MAX_VALUE          100
 | ||
|  | #define APP_PWM_FREQ_MIN_VALUE                4    //uint: kHz
 | ||
|  | #define APP_PWM_FREQ_MAX_VALUE                62   //uint: kHz
 | ||
|  | #define APP_PWM_MODE_MAX_VALUE                2
 | ||
|  | #define APP_PWM_ADJUST_TIME_MAX_VALUE         100
 | ||
|  | 
 | ||
|  | #define ADJUST_TOTAL_TIME                     3000
 | ||
|  | #define ADJUST_PWM_STEPS                      1
 | ||
|  | #define ADJUST_PWM_PERIOD                     10  /* ms */
 | ||
|  | #define STATE_SAVE_FLASH                      1
 | ||
|  | #define STATE_NO_SAVE                         0
 | ||
|  | #define PWM_FREQ_DEF_VAL                      5  /* default freq,unit:khz */
 | ||
|  | 
 | ||
|  | typedef enum { | ||
|  |     APP_PIN_UNKNOWN      = 0,       /* UNKNOWN */ | ||
|  |     APP_PIN_GPIO         = 1,       /* GPIO out mode */ | ||
|  |     APP_PIN_PWM          = 2,       /* PWM mode */ | ||
|  |     APP_PIN_GPIO_IN      = 3,       /* GPIO in mode */ | ||
|  | } app_pin_type_e; | ||
|  | 
 | ||
|  | typedef enum { | ||
|  |     APP_PWM_CTL_REALTIME = 0,   /* real-time control */ | ||
|  |     APP_PWM_CTL_LINAR = 1,      /* linear gradient */ | ||
|  |     APP_PWM_CTL_LOGAR = 2,      /* logar gradient */ | ||
|  | } app_pwm_ctl_mode_e; | ||
|  | 
 | ||
|  | /* GPIO number */ | ||
|  | typedef enum { | ||
|  |     HI_GPIO_IDX_0  = 0,     /* GPIO0 */ | ||
|  |     HI_GPIO_IDX_1  = 1,     /* GPIO1 */ | ||
|  |     HI_GPIO_IDX_4  = 4,     /* GPIO4 */ | ||
|  |     HI_GPIO_IDX_7  = 7,     /* GPIO7 */ | ||
|  |     HI_GPIO_IDX_8  = 8,     /* GPIO8 */ | ||
|  |     HI_GPIO_IDX_9  = 9,     /* GPIO9 */ | ||
|  |     HI_GPIO_IDX_10 = 10,    /* GPIO10 */ | ||
|  |     HI_GPIO_IDX_22 = 22,    /* GPIO22 */ | ||
|  |     HI_GPIO_IDX_23 = 23,    /* GPIO23 */ | ||
|  |     HI_GPIO_IDX_26 = 26,    /* GPIO26 */ | ||
|  |     HI_GPIO_IDX_28 = 28,    /* GPIO28 */ | ||
|  |     HI_GPIO_IDX_31 = 31,    /* GPIO31 */ | ||
|  |     HI_GPIO_IDX_32 = 32,    /* GPIO32 */ | ||
|  |     HI_GPIO_IDX_33 = 33,    /* GPIO33 */ | ||
|  |     HI_GPIO_IDX_34 = 34,    /* GPIO34 */ | ||
|  |     HI_GPIO_IDX_35 = 35,    /* GPIO35 */ | ||
|  |     HI_GPIO_IDX_36 = 36,    /* GPIO36 */ | ||
|  |     HI_GPIO_IDX_37 = 37,    /* GPIO37 */ | ||
|  |     HI_GPIO_IDX_38 = 38,    /* GPIO38 */ | ||
|  |     HI_GPIO_IDX_39 = 39,    /* GPIO39 */ | ||
|  |     HI_GPIO_IDX_40 = 40,    /* GPIO40 */ | ||
|  |     HI_GPIO_IDX_41 = 41,    /* GPIO41 */ | ||
|  |     HI_GPIO_IDX_42 = 42,    /* GPIO42 */ | ||
|  |     HI_GPIO_IDX_MAX,        /* Max value, can not be used */ | ||
|  | } app_gpio_idx_e; | ||
|  | 
 | ||
|  | #pragma pack(push)  // save the pack status
 | ||
|  | #pragma pack(1)     // 1 byte align
 | ||
|  | 
 | ||
|  | typedef struct { | ||
|  |     uint16_t duration; | ||
|  |     uint16_t times; | ||
|  |     uint16_t current_val; | ||
|  |     uint16_t end_val; | ||
|  |     uint8_t timer_init; | ||
|  | } pwm_adjust_state; | ||
|  | 
 | ||
|  | #pragma pack(pop)    /* restore the pack status */
 | ||
|  | 
 | ||
|  | void app_restore_hwio(void); | ||
|  | uint8_t app_get_hw_io_array_size(void); | ||
|  | uint8_t app_get_io_num(uint8_t pin[], uint8_t size); | ||
|  | bool_t app_check_io_state_param(app_io_state *io_state); | ||
|  | void app_pwm_config(uint8_t ch, uint8_t gpio_p, uint32_t pwm_freq, | ||
|  |     uint32_t pwm_duty); | ||
|  | 
 | ||
|  | /**
 | ||
|  |  * @brief app_pwm_get_usable_channel() - Get unused PWM channel. | ||
|  |  * | ||
|  |  * @return IOT_PWM_CHANNEL_0 ~ n -- usable channel. | ||
|  |  * @return IOT_PWM_CHANNEL_INVAL -- no usable channel . | ||
|  |  */ | ||
|  | uint8_t app_pwm_get_usable_channel(void); | ||
|  | uint16_t app_get_io_map(app_io_state *io_state); | ||
|  | uint16_t app_get_gpio_state(app_io_state *io_state); | ||
|  | uint16_t app_set_gpio_state(app_io_state *io_state, uint8_t save_flash); | ||
|  | void app_io_init(void); | ||
|  | 
 | ||
|  | #ifdef __cplusplus
 | ||
|  |  } | ||
|  | #endif
 | ||
|  | 
 | ||
|  | #endif  /* _APP_GPIO_H_ */
 | ||
|  | 
 | ||
|  | 
 |