gpio_8258.h
Go to the documentation of this file.
1 /********************************************************************************************************
2  * @file gpio_8258.h
3  *
4  * @brief This is the header file for TLSR8258
5  *
6  * @author Driver Group
7  * @date May 8, 2018
8  *
9  * @par Copyright (c) 2018, Telink Semiconductor (Shanghai) Co., Ltd.
10  * All rights reserved.
11  *
12  * The information contained herein is confidential property of Telink
13  * Semiconductor (Shanghai) Co., Ltd. and is available under the terms
14  * of Commercial License Agreement between Telink Semiconductor (Shanghai)
15  * Co., Ltd. and the licensee or the terms described here-in. This heading
16  * MUST NOT be removed from this file.
17  *
18  * Licensees are granted free, non-transferable use of the information in this
19  * file under Mutual Non-Disclosure Agreement. NO WARRENTY of ANY KIND is provided.
20  * @par History:
21  * 1.initial release(DEC. 26 2018)
22  *
23  * @version A001
24  *
25  *******************************************************************************************************/
26 
27 #pragma once
28 
29 #include "register.h"
30 #include "gpio.h"
31 #include "analog.h"
32 
33 
38 typedef enum{
39  GPIO_GROUPA = 0x000,
40  GPIO_GROUPB = 0x100,
41  GPIO_GROUPC = 0x200,
42  GPIO_GROUPD = 0x300,
43  GPIO_GROUPE = 0x400,
44 
53  GPIOA_ALL = GPIO_GROUPA | 0x00ff,
54 
63 
72 
81 
86 
87  GPIO_ALL = 0x500,
89 
94 typedef enum{
95  AS_GPIO = 0,
96  AS_MSPI = 1,
97  AS_SWIRE = 2,
98  AS_UART = 3,
99  AS_I2C = 4,
100  AS_SPI = 5,
101  AS_I2S = 6,
102  AS_AMIC = 7,
103  AS_DMIC = 8,
104  AS_SDM = 9,
105  AS_USB = 10,
106  AS_ADC = 11,
107  AS_CMP = 12,
108  AS_ATS = 13,
109 
110  AS_PWM0 = 20,
111  AS_PWM1 = 21,
112  AS_PWM2 = 22,
113  AS_PWM3 = 23,
114  AS_PWM4 = 24,
115  AS_PWM5 = 25,
116  AS_PWM0_N = 26,
117  AS_PWM1_N = 27,
118  AS_PWM2_N = 28,
119  AS_PWM3_N = 29,
120  AS_PWM4_N = 30,
121  AS_PWM5_N = 31,
123 
124 
125 typedef enum{
129 
130 
131 
135 typedef enum{
139 
143 typedef enum {
149 
150 
156 void gpio_init(int anaRes_init_en);
157 
165 
172 static inline void gpio_set_output_en(GPIO_PinTypeDef pin, unsigned int value)
173 {
174  unsigned char bit = pin & 0xff;
175  if(!value){
176  BM_SET(reg_gpio_oen(pin), bit);
177  }else{
178  BM_CLR(reg_gpio_oen(pin), bit);
179  }
180 }
181 
188 void gpio_set_input_en(GPIO_PinTypeDef pin, unsigned int value);
189 
196 static inline int gpio_is_output_en(GPIO_PinTypeDef pin)
197 {
198  return !BM_IS_SET(reg_gpio_oen(pin), pin & 0xff);
199 }
200 
207 static inline int gpio_is_input_en(GPIO_PinTypeDef pin)
208 {
209  return BM_IS_SET(reg_gpio_ie(pin), pin & 0xff);
210 }
211 
218 static inline void gpio_write(GPIO_PinTypeDef pin, unsigned int value)
219 {
220  unsigned char bit = pin & 0xff;
221  if(value){
222  BM_SET(reg_gpio_out(pin), bit);
223  }else{
224  BM_CLR(reg_gpio_out(pin), bit);
225  }
226 }
227 
233 static inline unsigned int gpio_read(GPIO_PinTypeDef pin)
234 {
235  return BM_IS_SET(reg_gpio_in(pin), pin & 0xff);
236 }
243 static inline unsigned int gpio_read_cache(GPIO_PinTypeDef pin, unsigned char *p)
244 {
245  return p[pin>>8] & (pin & 0xff);
246 }
247 
253 static inline void gpio_read_all(unsigned char *p)
254 {
255  p[0] = REG_ADDR8(0x580);
256  p[1] = REG_ADDR8(0x588);
257  p[2] = REG_ADDR8(0x590);
258  p[3] = REG_ADDR8(0x598);
259 }
260 
266 static inline void gpio_toggle(GPIO_PinTypeDef pin)
267 {
268  reg_gpio_out(pin) ^= (pin & 0xFF);
269 }
270 
277 void gpio_set_data_strength(GPIO_PinTypeDef pin, unsigned int value);
278 
287 
294 
302 {
303  unsigned char bit = pin & 0xff;
304  if(falling){
305  BM_SET(reg_gpio_pol(pin), bit);
306  }else{
307  BM_CLR(reg_gpio_pol(pin), bit);
308  }
309 }
310 
317 static inline void gpio_set_interrupt(GPIO_PinTypeDef pin, GPIO_PolTypeDef falling)
318 {
319  unsigned char bit = pin & 0xff;
320  BM_SET(reg_gpio_irq_wakeup_en(pin), bit);
323  if(falling){
324  BM_SET(reg_gpio_pol(pin), bit);
325  }else{
326  BM_CLR(reg_gpio_pol(pin), bit);
327  }
328 }
329 
336 static inline void gpio_en_interrupt(GPIO_PinTypeDef pin, int en) // reg_irq_mask: FLD_IRQ_GPIO_EN
337 {
338  unsigned char bit = pin & 0xff;
339  if(en){
340  BM_SET(reg_gpio_irq_wakeup_en(pin), bit);
341  }
342  else{
343  BM_CLR(reg_gpio_irq_wakeup_en(pin), bit);
344  }
345 }
346 
354  unsigned char bit = pin & 0xff;
355  BM_SET(reg_gpio_irq_risc0_en(pin), bit);
357  if(falling){
358  BM_SET(reg_gpio_pol(pin), bit);
359  }else{
360  BM_CLR(reg_gpio_pol(pin), bit);
361  }
362 }
363 
364 
371 static inline void gpio_en_interrupt_risc0(GPIO_PinTypeDef pin, int en) // reg_irq_mask: FLD_IRQ_GPIO_RISC0_EN
372 {
373  unsigned char bit = pin & 0xff;
374  if(en){
375  BM_SET(reg_gpio_irq_risc0_en(pin), bit);
376  }
377  else{
378  BM_CLR(reg_gpio_irq_risc0_en(pin), bit);
379  }
380 }
381 
382 
390 {
391  unsigned char bit = pin & 0xff;
392  BM_SET(reg_gpio_irq_risc1_en(pin), bit);
394  if(falling){
395  BM_SET(reg_gpio_pol(pin), bit);
396  }else{
397  BM_CLR(reg_gpio_pol(pin), bit);
398  }
399 }
400 
407 static inline void gpio_en_interrupt_risc1(GPIO_PinTypeDef pin, int en) // reg_irq_mask: FLD_IRQ_GPIO_RISC1_EN
408 {
409  unsigned char bit = pin & 0xff;
410  if(en){
411  BM_SET(reg_gpio_irq_risc1_en(pin), bit);
412  }
413  else{
414  BM_CLR(reg_gpio_irq_risc1_en(pin), bit);
415  }
416 }
417 
424 static inline void usb_dp_pullup_en (int en)
425 {
426  unsigned char dat = analog_read(0x0b);
427  if (en) {
428  dat = dat | BIT(7);
429  }
430  else
431  {
432  dat = dat & 0x7f ;
433  }
434 
435  analog_write (0x0b, dat);
436 }
437 
443 static inline void usb_power_on(unsigned char en)
444 {
445  if(en)
446  {
447  analog_write(0x34,analog_read(0x34)|0x02);
448  }
449  else
450  {
451  analog_write(0x34,analog_read(0x34)&0xfd);
452  }
453 }
459 static inline void usb_set_pin_en(void)
460 {
463  usb_dp_pullup_en (1);
464 }
465 
466  //end of GP5
589 
590 
591 
592 
Definition: gpio_8258.h:103
unsigned char analog_read(unsigned char addr)
This function serves to analog register read.
Definition: gpio_8258.h:98
Definition: gpio_8258.h:107
Definition: gpio_8258.h:58
static void gpio_set_output_en(GPIO_PinTypeDef pin, unsigned int value)
This function set the output function of a pin.
Definition: gpio_8258.h:172
void gpio_set_input_en(GPIO_PinTypeDef pin, unsigned int value)
This function set the input function of a pin.
Definition: gpio_8258.h:47
#define reg_gpio_in(i)
Definition: register_8258.h:676
Definition: gpio_8258.h:70
Definition: gpio_8258.h:106
#define BM_IS_SET(x, mask)
Definition: bsp.h:41
Definition: gpio_8258.h:121
Definition: gpio_8258.h:56
Definition: gpio_8258.h:147
Definition: gpio_8258.h:73
Definition: gpio_8258.h:51
Definition: gpio_8258.h:83
Definition: gpio_8258.h:137
Definition: gpio_8258.h:49
static int gpio_is_input_en(GPIO_PinTypeDef pin)
This function determines whether the input function of a pin is enabled.
Definition: gpio_8258.h:207
Definition: gpio_8258.h:69
Definition: gpio_8258.h:80
GPIO_PolTypeDef
Define rising/falling types.
Definition: gpio_8258.h:135
static void gpio_set_interrupt_risc0(GPIO_PinTypeDef pin, GPIO_PolTypeDef falling)
This function set a pin's IRQ.
Definition: gpio_8258.h:353
Definition: gpio_8258.h:52
#define reg_gpio_oen(i)
Definition: register_8258.h:678
static void usb_set_pin_en(void)
This function serves to set GPIO MUX function as DP and DM pin of USB.
Definition: gpio_8258.h:459
static void gpio_en_interrupt(GPIO_PinTypeDef pin, int en)
This function enables a pin's IRQ function.
Definition: gpio_8258.h:336
static void gpio_read_all(unsigned char *p)
This function read all the pins' input level.
Definition: gpio_8258.h:253
Definition: gpio_8258.h:102
static void gpio_write(GPIO_PinTypeDef pin, unsigned int value)
This function set the pin's output level.
Definition: gpio_8258.h:218
Definition: gpio_8258.h:51
#define BM_SET(x, mask)
Definition: bsp.h:39
Definition: gpio_8258.h:115
Definition: gpio_8258.h:68
Definition: gpio_8258.h:136
Definition: gpio_8258.h:118
void gpio_setup_up_down_resistor(GPIO_PinTypeDef gpio, GPIO_PullTypeDef up_down)
This function set a pin's pull-up/down resistor.
Definition: gpio_8258.h:66
Definition: gpio_8258.h:101
#define reg_gpio_irq_wakeup_en(i)
Definition: register_8258.h:686
Definition: gpio_8258.h:83
Definition: gpio_8258.h:67
void gpio_init(int anaRes_init_en)
This function servers to initialization all gpio.
#define BIT(n)
Definition: bsp.h:33
void gpio_shutdown(GPIO_PinTypeDef pin)
This function servers to set the specified GPIO as high resistor.
Definition: gpio_8258.h:82
Definition: gpio_8258.h:85
static unsigned int gpio_read(GPIO_PinTypeDef pin)
This function read the pin's input/output level.
Definition: gpio_8258.h:233
Definition: gpio_8258.h:84
Definition: gpio_8258.h:127
Definition: gpio_8258.h:99
static void usb_dp_pullup_en(int en)
This function enables or disables the internal pull-up resistor of DP pin of USB interface.
Definition: gpio_8258.h:424
#define reg_gpio_ie(i)
Definition: register_8258.h:677
Definition: gpio_8258.h:64
Definition: gpio_8258.h:108
Definition: gpio_8258.h:71
Definition: gpio_8258.h:53
#define REG_ADDR8(a)
Definition: bsp.h:102
Definition: register_8258.h:792
Definition: gpio_8258.h:136
Definition: gpio_8258.h:55
Definition: gpio_8258.h:62
Definition: gpio_8258.h:76
Definition: gpio_8258.h:111
#define reg_gpio_irq_risc0_en(i)
Definition: register_8258.h:688
Definition: gpio_8258.h:45
Definition: gpio_8258.h:146
Definition: gpio_8258.h:65
Definition: register_8258.h:796
Definition: gpio_8258.h:84
Definition: gpio_8258.h:50
static int gpio_is_output_en(GPIO_PinTypeDef pin)
This function determines whether the output function of a pin is enabled.
Definition: gpio_8258.h:196
Definition: gpio_8258.h:85
Definition: gpio_8258.h:75
Definition: gpio_8258.h:39
GPIO_PullTypeDef
Define pull up or down types.
Definition: gpio_8258.h:143
static void gpio_toggle(GPIO_PinTypeDef pin)
This function set the pin toggle.
Definition: gpio_8258.h:266
GPIO_PinTypeDef
Define GPIO types.
Definition: gpio_8258.h:38
Definition: gpio_8258.h:114
Definition: gpio_8258.h:119
Definition: gpio_8258.h:113
Definition: gpio_8258.h:145
Definition: gpio_8258.h:120
static void usb_power_on(unsigned char en)
This function serves to power on or down USB module.
Definition: gpio_8258.h:443
static void gpio_set_interrupt(GPIO_PinTypeDef pin, GPIO_PolTypeDef falling)
This function set a pin's IRQ.
Definition: gpio_8258.h:317
GPIO_FuncTypeDef
Define GPIO Function types.
Definition: gpio_8258.h:94
Definition: gpio_8258.h:126
void gpio_set_data_strength(GPIO_PinTypeDef pin, unsigned int value)
This function set the pin's driving strength.
Definition: gpio_8258.h:104
Definition: gpio_8258.h:110
Definition: gpio_8258.h:78
Definition: gpio_8258.h:97
Definition: gpio_8258.h:57
void analog_write(unsigned char addr, unsigned char v)
This function serves to analog register write.
Definition: gpio_8258.h:41
#define reg_gpio_irq_risc1_en(i)
Definition: register_8258.h:689
Definition: gpio_8258.h:117
#define reg_gpio_out(i)
Definition: register_8258.h:679
Definition: gpio_8258.h:100
#define reg_irq_mask
Definition: register_8258.h:767
Definition: gpio_8258.h:43
static void gpio_set_interrupt_pol(GPIO_PinTypeDef pin, GPIO_PolTypeDef falling)
This function set a pin's polarity that trig its IRQ.
Definition: gpio_8258.h:301
Definition: gpio_8258.h:112
Definition: register_8258.h:704
Definition: gpio_8258.h:137
Definition: gpio_8258.h:105
static void gpio_en_interrupt_risc0(GPIO_PinTypeDef pin, int en)
This function enables a pin's IRQ function.
Definition: gpio_8258.h:371
Definition: gpio_8258.h:87
static unsigned int gpio_read_cache(GPIO_PinTypeDef pin, unsigned char *p)
This function read a pin's cache from the buffer.
Definition: gpio_8258.h:243
Definition: gpio_8258.h:116
#define BM_CLR(x, mask)
Definition: bsp.h:40
Definition: gpio_8258.h:50
Definition: gpio_8258.h:40
Definition: gpio_8258.h:95
Definition: gpio_8258.h:82
Definition: gpio_8258.h:42
Definition: gpio_8258.h:59
Definition: gpio_8258.h:61
Definition: register_8258.h:795
Definition: gpio_8258.h:46
Definition: gpio_8258.h:77
Definition: gpio_8258.h:96
Definition: gpio_8258.h:48
GPIO_LevelTypeDef
Definition: gpio_8258.h:125
Definition: gpio_8258.h:144
#define reg_gpio_pol(i)
Definition: register_8258.h:680
static void gpio_en_interrupt_risc1(GPIO_PinTypeDef pin, int en)
This function enables a pin's IRQ function.
Definition: gpio_8258.h:407
void gpio_set_func(GPIO_PinTypeDef pin, GPIO_FuncTypeDef func)
This function servers to set the GPIO's function.
Definition: gpio_8258.h:74
#define reg_gpio_wakeup_irq
Definition: register_8258.h:701
static void gpio_set_interrupt_risc1(GPIO_PinTypeDef pin, GPIO_PolTypeDef falling)
This function set a pin's IRQ.
Definition: gpio_8258.h:389
Definition: gpio_8258.h:79
Definition: gpio_8258.h:60
Definition: gpio_8258.h:52