Contiki-NG
Loading...
Searching...
No Matches
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 | \
47 IOC_IOMODE_OPEN_SRC_INV | IOC_HYST_ENABLE)
48/*---------------------------------------------------------------------------*/
49void
51{
52 /* Get current settings */
53 uint32_t config = ti_lib_ioc_port_configure_get(pin);
54
55 /* Check if we are enabling interrupts now */
56 bool enabling_interrupts =
57 (config & IOC_INT_ENABLE) == 0 && (cfg & GPIO_HAL_PIN_CFG_INT_ENABLE);
58
59 /* Clear settings that we are about to change, keep everything else */
60 config &= ~CONFIG_MASK;
61
62 /* Hysteresis */
63 gpio_hal_pin_cfg_t tmp = cfg & GPIO_HAL_PIN_CFG_HYSTERESIS;
64 if(tmp == GPIO_HAL_PIN_CFG_HYSTERESIS) {
65 config |= IOC_HYST_ENABLE;
66 } else {
67 config |= IOC_HYST_DISABLE;
68 }
69
70 /* Edge detection */
71 tmp = cfg & GPIO_HAL_PIN_CFG_EDGE_BOTH;
72 if(tmp == GPIO_HAL_PIN_CFG_EDGE_NONE) {
73 config |= IOC_NO_EDGE;
74 } else if(tmp == GPIO_HAL_PIN_CFG_EDGE_RISING) {
75 config |= IOC_RISING_EDGE;
76 } else if(tmp == GPIO_HAL_PIN_CFG_EDGE_FALLING) {
77 config |= IOC_FALLING_EDGE;
78 } else if(tmp == GPIO_HAL_PIN_CFG_EDGE_BOTH) {
79 config |= IOC_BOTH_EDGES;
80 }
81
82 /* Pull */
83 tmp = cfg & GPIO_HAL_PIN_CFG_PULL_MASK;
84 if(tmp == GPIO_HAL_PIN_CFG_PULL_NONE) {
85 config |= IOC_NO_IOPULL;
86 } else if(tmp == GPIO_HAL_PIN_CFG_PULL_DOWN) {
87 config |= IOC_IOPULL_DOWN;
88 } else if(tmp == GPIO_HAL_PIN_CFG_PULL_UP) {
89 config |= IOC_IOPULL_UP;
90 }
91
92 /* Interrupt enable/disable */
93 tmp = cfg & GPIO_HAL_PIN_CFG_INT_MASK;
94 if(tmp == GPIO_HAL_PIN_CFG_INT_DISABLE) {
95 config |= IOC_INT_DISABLE;
96 } else if(tmp == GPIO_HAL_PIN_CFG_INT_ENABLE) {
97 config |= IOC_INT_ENABLE;
98 }
99
100 if(enabling_interrupts) {
101 ti_lib_gpio_clear_event_dio(pin);
102 }
103 ti_lib_ioc_port_configure_set(pin, IOC_PORT_GPIO, config);
104}
105/*---------------------------------------------------------------------------*/
108{
110 uint32_t tmp;
111 uint32_t config;
112
113 cfg = 0;
114 config = ti_lib_ioc_port_configure_get(pin);
115
116 /* Hysteresis */
117 tmp = config & IOC_HYST_ENABLE;
118 if(tmp == IOC_HYST_ENABLE) {
119 cfg |= GPIO_HAL_PIN_CFG_HYSTERESIS;
120 }
121
122 /* Pull */
123 tmp = config & IOC_IOPULL_M;
124 if(tmp == IOC_IOPULL_UP) {
125 cfg |= GPIO_HAL_PIN_CFG_PULL_UP;
126 } else if(tmp == IOC_IOPULL_DOWN) {
127 cfg |= GPIO_HAL_PIN_CFG_PULL_DOWN;
128 } else if(tmp == IOC_NO_IOPULL) {
129 cfg |= GPIO_HAL_PIN_CFG_PULL_NONE;
130 }
131
132 /* Interrupt enable/disable */
133 tmp = config & IOC_INT_ENABLE;
134 if(tmp == IOC_INT_DISABLE) {
135 cfg |= GPIO_HAL_PIN_CFG_INT_DISABLE;
136 } else if(tmp == IOC_INT_ENABLE) {
137 cfg |= GPIO_HAL_PIN_CFG_INT_ENABLE;
138 }
139
140 /* Edge detection */
141 tmp = config & IOC_BOTH_EDGES;
142 if(tmp == IOC_NO_EDGE) {
143 cfg |= GPIO_HAL_PIN_CFG_EDGE_NONE;
144 } else if(tmp == IOC_FALLING_EDGE) {
145 cfg |= GPIO_HAL_PIN_CFG_EDGE_FALLING;
146 } else if(tmp == IOC_RISING_EDGE) {
147 cfg |= GPIO_HAL_PIN_CFG_EDGE_RISING;
148 } else if(tmp == IOC_BOTH_EDGES) {
149 cfg |= GPIO_HAL_PIN_CFG_EDGE_BOTH;
150 }
151
152 return cfg;
153}
154/*---------------------------------------------------------------------------*/
157{
158 gpio_hal_pin_mask_t oe_pins;
159
160 /* For pins configured as output we need to read DOUT31_0 */
161 oe_pins = ti_lib_gpio_get_output_enable_multi_dio(pins);
162
163 pins &= ~oe_pins;
164
165 return (HWREG(GPIO_BASE + GPIO_O_DOUT31_0) & oe_pins) |
166 ti_lib_gpio_read_multi_dio(pins);
167}
168/*---------------------------------------------------------------------------*/
169uint8_t
171{
172 if(ti_lib_gpio_get_output_enable_dio(pin)) {
173 return (HWREG(GPIO_BASE + GPIO_O_DOUT31_0) >> pin) & 1;
174 }
175
176 return ti_lib_gpio_read_dio(pin);
177}
178/*---------------------------------------------------------------------------*/
179/** @} */
Header file for the GPIO HAL.
gpio_hal_pin_mask_t gpio_hal_arch_no_port_read_pins(gpio_hal_pin_mask_t pins)
Read multiple pins.
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.
void gpio_hal_arch_no_port_pin_cfg_set(gpio_hal_pin_t pin, gpio_hal_pin_cfg_t cfg)
Configure a gpio pin.
uint8_t gpio_hal_arch_no_port_read_pin(gpio_hal_pin_t pin)
Read a GPIO pin.
uint32_t gpio_hal_pin_mask_t
GPIO pin mask representation.
Definition gpio-hal.h:142
uint32_t gpio_hal_pin_cfg_t
GPIO pin configuration.
Definition gpio-hal.h:118
uint8_t gpio_hal_pin_t
GPIO pin number representation.
Definition gpio-hal.h:103
Header file with macros which rename TI CC26xxware functions.