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 "dev/gpio-hal.h"
43 
44 #include <stdint.h>
45 /*---------------------------------------------------------------------------*/
46 #define CONFIG_MASK (IOC_IOPULL_M | IOC_INT_M | IOC_IOMODE_OPEN_SRC_INV)
47 /*---------------------------------------------------------------------------*/
48 void
50 {
51  uint32_t config;
53 
54  /* Clear settings that we are about to change, keep everything else */
55  config = ti_lib_ioc_port_configure_get(pin);
56  config &= ~CONFIG_MASK;
57 
58  tmp = cfg & GPIO_HAL_PIN_CFG_EDGE_BOTH;
59  if(tmp == GPIO_HAL_PIN_CFG_EDGE_NONE) {
60  config |= IOC_NO_EDGE;
61  } else if(tmp == GPIO_HAL_PIN_CFG_EDGE_RISING) {
62  config |= IOC_RISING_EDGE;
63  } else if(tmp == GPIO_HAL_PIN_CFG_EDGE_FALLING) {
64  config |= IOC_FALLING_EDGE;
65  } else if(tmp == GPIO_HAL_PIN_CFG_EDGE_BOTH) {
66  config |= IOC_BOTH_EDGES;
67  }
68 
69  tmp = cfg & GPIO_HAL_PIN_CFG_PULL_MASK;
70  if(tmp == GPIO_HAL_PIN_CFG_PULL_NONE) {
71  config |= IOC_NO_IOPULL;
72  } else if(tmp == GPIO_HAL_PIN_CFG_PULL_DOWN) {
73  config |= IOC_IOPULL_DOWN;
74  } else if(tmp == GPIO_HAL_PIN_CFG_PULL_UP) {
75  config |= IOC_IOPULL_UP;
76  }
77 
78  tmp = cfg & GPIO_HAL_PIN_CFG_INT_MASK;
79  if(tmp == GPIO_HAL_PIN_CFG_INT_DISABLE) {
80  config |= IOC_INT_DISABLE;
81  } else if(tmp == GPIO_HAL_PIN_CFG_INT_ENABLE) {
82  config |= IOC_INT_ENABLE;
83  }
84 
85  ti_lib_ioc_port_configure_set(pin, IOC_PORT_GPIO, config);
86 }
87 /*---------------------------------------------------------------------------*/
90 {
92  uint32_t tmp;
93  uint32_t config;
94 
95  cfg = 0;
96  config = ti_lib_ioc_port_configure_get(pin);
97 
98  /* Pull */
99  tmp = config & IOC_IOPULL_M;
100  if(tmp == IOC_IOPULL_UP) {
101  cfg |= GPIO_HAL_PIN_CFG_PULL_UP;
102  } else if(tmp == IOC_IOPULL_DOWN) {
103  cfg |= GPIO_HAL_PIN_CFG_PULL_DOWN;
104  } else if(tmp == IOC_NO_IOPULL) {
105  cfg |= GPIO_HAL_PIN_CFG_PULL_NONE;
106  }
107 
108  /* Interrupt enable/disable */
109  tmp = config & IOC_INT_ENABLE;
110  if(tmp == IOC_INT_DISABLE) {
111  cfg |= GPIO_HAL_PIN_CFG_INT_DISABLE;
112  } else if(tmp == IOC_INT_ENABLE) {
113  cfg |= GPIO_HAL_PIN_CFG_INT_ENABLE;
114  }
115 
116  /* Edge detection */
117  tmp = config & IOC_BOTH_EDGES;
118  if(tmp == IOC_NO_EDGE) {
119  cfg |= GPIO_HAL_PIN_CFG_EDGE_NONE;
120  } else if(tmp == IOC_FALLING_EDGE) {
121  cfg |= GPIO_HAL_PIN_CFG_EDGE_FALLING;
122  } else if(tmp == IOC_RISING_EDGE) {
123  cfg |= GPIO_HAL_PIN_CFG_EDGE_RISING;
124  } else if(tmp == IOC_BOTH_EDGES) {
125  cfg |= GPIO_HAL_PIN_CFG_EDGE_BOTH;
126  }
127 
128  return cfg;
129 }
130 /*---------------------------------------------------------------------------*/
133 {
134  gpio_hal_pin_mask_t oe_pins;
135 
136  /* For pins configured as output we need to read DOUT31_0 */
137  oe_pins = ti_lib_gpio_get_output_enable_multi_dio(pins);
138 
139  pins &= ~oe_pins;
140 
141  return (HWREG(GPIO_BASE + GPIO_O_DOUT31_0) & oe_pins) |
142  ti_lib_gpio_read_multi_dio(pins);
143 }
144 /*---------------------------------------------------------------------------*/
145 uint8_t
147 {
148  if(ti_lib_gpio_get_output_enable_dio(pin)) {
149  return (HWREG(GPIO_BASE + GPIO_O_DOUT31_0) >> pin) & 1;
150  }
151 
152  return ti_lib_gpio_read_dio(pin);
153 }
154 /*---------------------------------------------------------------------------*/
155 /** @} */
Header file with macros which rename TI CC26xxware functions.
gpio_hal_pin_mask_t gpio_hal_arch_no_port_read_pins(gpio_hal_pin_mask_t pins)
Read multiple pins.
uint8_t gpio_hal_pin_t
GPIO pin number representation.
Definition: gpio-hal.h:103
void gpio_hal_arch_no_port_pin_cfg_set(gpio_hal_pin_t pin, gpio_hal_pin_cfg_t cfg)
Configure a gpio pin.
Definition: gpio-hal-arch.c:48
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:142
gpio_hal_pin_cfg_t gpio_hal_arch_no_port_pin_cfg_get(gpio_hal_pin_t pin)
Read the configuration of a GPIO pin.
Definition: gpio-hal-arch.c:97
uint8_t gpio_hal_arch_no_port_read_pin(gpio_hal_pin_t pin)
Read a GPIO pin.
Header file for the GPIO HAL.
uint32_t gpio_hal_pin_cfg_t
GPIO pin configuration.
Definition: gpio-hal.h:118