Contiki-NG
gpio-hal-arch.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017, George Oikonomou - http://www.spd.gr
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the distribution.
14  * 3. Neither the name of the copyright holder nor the names of its
15  * contributors may be used to endorse or promote products derived
16  * from this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
23  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
27  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
29  * OF THE POSSIBILITY OF SUCH DAMAGE.
30  */
31 /*---------------------------------------------------------------------------*/
32 /**
33  * \addtogroup cc26xx-gpio-hal
34  * @{
35  *
36  * \file
37  * Implementation file for the CC13xx/CC26xx GPIO HAL functions
38  */
39 /*---------------------------------------------------------------------------*/
40 #include "contiki.h"
41 #include "ti-lib.h"
42 #include "ti-lib-rom.h"
43 #include "dev/gpio-hal.h"
44 
45 #include <stdint.h>
46 /*---------------------------------------------------------------------------*/
47 #define CONFIG_MASK (IOC_IOPULL_M | IOC_INT_M | IOC_IOMODE_OPEN_SRC_INV)
48 /*---------------------------------------------------------------------------*/
49 void
51 {
52  uint32_t config;
54 
55  /* Clear settings that we are about to change, keep everything else */
56  config = ti_lib_rom_ioc_port_configure_get(pin);
57  config &= ~CONFIG_MASK;
58 
59  tmp = cfg & GPIO_HAL_PIN_CFG_EDGE_BOTH;
60  if(tmp == GPIO_HAL_PIN_CFG_EDGE_NONE) {
61  config |= IOC_NO_EDGE;
62  } else if(tmp == GPIO_HAL_PIN_CFG_EDGE_RISING) {
63  config |= IOC_RISING_EDGE;
64  } else if(tmp == GPIO_HAL_PIN_CFG_EDGE_FALLING) {
65  config |= IOC_FALLING_EDGE;
66  } else if(tmp == GPIO_HAL_PIN_CFG_EDGE_BOTH) {
67  config |= IOC_BOTH_EDGES;
68  }
69 
70  tmp = cfg & GPIO_HAL_PIN_CFG_PULL_MASK;
71  if(tmp == GPIO_HAL_PIN_CFG_PULL_NONE) {
72  config |= IOC_NO_IOPULL;
73  } else if(tmp == GPIO_HAL_PIN_CFG_PULL_DOWN) {
74  config |= IOC_IOPULL_DOWN;
75  } else if(tmp == GPIO_HAL_PIN_CFG_PULL_UP) {
76  config |= IOC_IOPULL_UP;
77  }
78 
79  tmp = cfg & GPIO_HAL_PIN_CFG_INT_MASK;
80  if(tmp == GPIO_HAL_PIN_CFG_INT_DISABLE) {
81  config |= IOC_INT_DISABLE;
82  } else if(tmp == GPIO_HAL_PIN_CFG_INT_ENABLE) {
83  config |= IOC_INT_ENABLE;
84  }
85 
86  ti_lib_rom_ioc_port_configure_set(pin, IOC_PORT_GPIO, config);
87 }
88 /*---------------------------------------------------------------------------*/
91 {
93  uint32_t tmp;
94  uint32_t config;
95 
96  cfg = 0;
97  config = ti_lib_rom_ioc_port_configure_get(pin);
98 
99  /* Pull */
100  tmp = config & IOC_IOPULL_M;
101  if(tmp == IOC_IOPULL_UP) {
102  cfg |= GPIO_HAL_PIN_CFG_PULL_UP;
103  } else if(tmp == IOC_IOPULL_DOWN) {
104  cfg |= GPIO_HAL_PIN_CFG_PULL_DOWN;
105  } else if(tmp == IOC_NO_IOPULL) {
106  cfg |= GPIO_HAL_PIN_CFG_PULL_NONE;
107  }
108 
109  /* Interrupt enable/disable */
110  tmp = config & IOC_INT_ENABLE;
111  if(tmp == IOC_INT_DISABLE) {
112  cfg |= GPIO_HAL_PIN_CFG_INT_DISABLE;
113  } else if(tmp == IOC_INT_ENABLE) {
114  cfg |= GPIO_HAL_PIN_CFG_INT_ENABLE;
115  }
116 
117  /* Edge detection */
118  tmp = config & IOC_BOTH_EDGES;
119  if(tmp == IOC_NO_EDGE) {
120  cfg |= GPIO_HAL_PIN_CFG_EDGE_NONE;
121  } else if(tmp == IOC_FALLING_EDGE) {
122  cfg |= GPIO_HAL_PIN_CFG_EDGE_FALLING;
123  } else if(tmp == IOC_RISING_EDGE) {
124  cfg |= GPIO_HAL_PIN_CFG_EDGE_RISING;
125  } else if(tmp == IOC_BOTH_EDGES) {
126  cfg |= GPIO_HAL_PIN_CFG_EDGE_BOTH;
127  }
128 
129  return cfg;
130 }
131 /*---------------------------------------------------------------------------*/
134 {
135  gpio_hal_pin_mask_t oe_pins;
136 
137  /* For pins configured as output we need to read DOUT31_0 */
138  oe_pins = ti_lib_gpio_get_output_enable_multi_dio(pins);
139 
140  pins &= ~oe_pins;
141 
142  return (HWREG(GPIO_BASE + GPIO_O_DOUT31_0) & oe_pins) |
143  ti_lib_gpio_read_multi_dio(pins);
144 }
145 /*---------------------------------------------------------------------------*/
146 uint8_t
148 {
149  if(ti_lib_gpio_get_output_enable_dio(pin)) {
150  return (HWREG(GPIO_BASE + GPIO_O_DOUT31_0) >> pin) & 1;
151  }
152 
153  return ti_lib_gpio_read_dio(pin);
154 }
155 /*---------------------------------------------------------------------------*/
156 /** @} */
Header file with macros which rename TI CC26xxware functions.
gpio_hal_pin_cfg_t gpio_hal_arch_pin_cfg_get(gpio_hal_pin_t pin)
Read the configuration of a GPIO pin.
Definition: gpio-hal-arch.c:97
Header file with CC13xxware/CC26xxware ROM API.
gpio_hal_pin_mask_t gpio_hal_arch_read_pins(gpio_hal_pin_mask_t pins)
Read multiple pins.
uint8_t gpio_hal_pin_cfg_t
GPIO pin configuration.
Definition: gpio-hal.h:85
uint8_t gpio_hal_pin_t
GPIO pin number representation.
Definition: gpio-hal.h:77
static int config(int type, int c, nrf_drv_gpiote_pin_t pin)
Configuration function for the button sensor for all buttons.
uint32_t gpio_hal_pin_mask_t
GPIO pin mask representation.
Definition: gpio-hal.h:99
uint8_t gpio_hal_arch_read_pin(gpio_hal_pin_t pin)
Read a GPIO pin.
Header file for the GPIO HAL.
void gpio_hal_arch_pin_cfg_set(gpio_hal_pin_t pin, gpio_hal_pin_cfg_t cfg)
Configure a gpio pin.
Definition: gpio-hal-arch.c:48