iOSのBLEコントローラアプリ「RCBController」とmbed HRM1017を接続し、RCサーボモータを操作するテストプログラムです。
Dependencies: BLE_API_Native_IRC Servo mbed
Fork of BLE_RCBController by
- 古いBLEライブラリを使っているのでプラットフォームは”Nordic nRF51822”を選択してください。
- ライブラリ類はUpdateしないでください。コンパイルエラーになります。
うまく接続できない時は、iPhone/iPadのBluetoothをOFF->ONしてキャッシュをクリアしてみてください。
BLE_API_Native_IRC/hw/nRF51822n/nordic/nrf-sdk/nrf_gpio.h@0:8c643bfe55b7, 2014-07-10 (annotated)
- Committer:
- jksoft
- Date:
- Thu Jul 10 14:21:52 2014 +0000
- Revision:
- 0:8c643bfe55b7
??
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jksoft | 0:8c643bfe55b7 | 1 | #ifndef NRF_GPIO_H__ |
jksoft | 0:8c643bfe55b7 | 2 | #define NRF_GPIO_H__ |
jksoft | 0:8c643bfe55b7 | 3 | |
jksoft | 0:8c643bfe55b7 | 4 | #include "nordic_global.h" |
jksoft | 0:8c643bfe55b7 | 5 | #include "nrf51.h" |
jksoft | 0:8c643bfe55b7 | 6 | #include "nrf51_bitfields.h" |
jksoft | 0:8c643bfe55b7 | 7 | |
jksoft | 0:8c643bfe55b7 | 8 | /** |
jksoft | 0:8c643bfe55b7 | 9 | * @defgroup nrf_gpio GPIO abstraction |
jksoft | 0:8c643bfe55b7 | 10 | * @{ |
jksoft | 0:8c643bfe55b7 | 11 | * @ingroup nrf_drivers |
jksoft | 0:8c643bfe55b7 | 12 | * @brief GPIO pin abstraction and port abstraction for reading and writing byte-wise to GPIO ports. |
jksoft | 0:8c643bfe55b7 | 13 | * |
jksoft | 0:8c643bfe55b7 | 14 | * Here, the GPIO ports are defined as follows: |
jksoft | 0:8c643bfe55b7 | 15 | * - Port 0 -> pin 0-7 |
jksoft | 0:8c643bfe55b7 | 16 | * - Port 1 -> pin 8-15 |
jksoft | 0:8c643bfe55b7 | 17 | * - Port 2 -> pin 16-23 |
jksoft | 0:8c643bfe55b7 | 18 | * - Port 3 -> pin 24-31 |
jksoft | 0:8c643bfe55b7 | 19 | */ |
jksoft | 0:8c643bfe55b7 | 20 | |
jksoft | 0:8c643bfe55b7 | 21 | /** |
jksoft | 0:8c643bfe55b7 | 22 | * @enum nrf_gpio_port_dir_t |
jksoft | 0:8c643bfe55b7 | 23 | * @brief Enumerator used for setting the direction of a GPIO port. |
jksoft | 0:8c643bfe55b7 | 24 | */ |
jksoft | 0:8c643bfe55b7 | 25 | typedef enum |
jksoft | 0:8c643bfe55b7 | 26 | { |
jksoft | 0:8c643bfe55b7 | 27 | NRF_GPIO_PORT_DIR_OUTPUT, ///< Output |
jksoft | 0:8c643bfe55b7 | 28 | NRF_GPIO_PORT_DIR_INPUT ///< Input |
jksoft | 0:8c643bfe55b7 | 29 | } nrf_gpio_port_dir_t; |
jksoft | 0:8c643bfe55b7 | 30 | |
jksoft | 0:8c643bfe55b7 | 31 | /** |
jksoft | 0:8c643bfe55b7 | 32 | * @enum nrf_gpio_pin_dir_t |
jksoft | 0:8c643bfe55b7 | 33 | * Pin direction definitions. |
jksoft | 0:8c643bfe55b7 | 34 | */ |
jksoft | 0:8c643bfe55b7 | 35 | typedef enum |
jksoft | 0:8c643bfe55b7 | 36 | { |
jksoft | 0:8c643bfe55b7 | 37 | NRF_GPIO_PIN_DIR_INPUT, ///< Input |
jksoft | 0:8c643bfe55b7 | 38 | NRF_GPIO_PIN_DIR_OUTPUT ///< Output |
jksoft | 0:8c643bfe55b7 | 39 | } nrf_gpio_pin_dir_t; |
jksoft | 0:8c643bfe55b7 | 40 | |
jksoft | 0:8c643bfe55b7 | 41 | /** |
jksoft | 0:8c643bfe55b7 | 42 | * @enum nrf_gpio_port_select_t |
jksoft | 0:8c643bfe55b7 | 43 | * @brief Enumerator used for selecting between port 0 - 3. |
jksoft | 0:8c643bfe55b7 | 44 | */ |
jksoft | 0:8c643bfe55b7 | 45 | typedef enum |
jksoft | 0:8c643bfe55b7 | 46 | { |
jksoft | 0:8c643bfe55b7 | 47 | NRF_GPIO_PORT_SELECT_PORT0 = 0, ///< Port 0 (GPIO pin 0-7) |
jksoft | 0:8c643bfe55b7 | 48 | NRF_GPIO_PORT_SELECT_PORT1, ///< Port 1 (GPIO pin 8-15) |
jksoft | 0:8c643bfe55b7 | 49 | NRF_GPIO_PORT_SELECT_PORT2, ///< Port 2 (GPIO pin 16-23) |
jksoft | 0:8c643bfe55b7 | 50 | NRF_GPIO_PORT_SELECT_PORT3, ///< Port 3 (GPIO pin 24-31) |
jksoft | 0:8c643bfe55b7 | 51 | } nrf_gpio_port_select_t; |
jksoft | 0:8c643bfe55b7 | 52 | |
jksoft | 0:8c643bfe55b7 | 53 | /** |
jksoft | 0:8c643bfe55b7 | 54 | * @enum nrf_gpio_pin_pull_t |
jksoft | 0:8c643bfe55b7 | 55 | * @brief Enumerator used for selecting the pin to be pulled down or up at the time of pin configuration |
jksoft | 0:8c643bfe55b7 | 56 | */ |
jksoft | 0:8c643bfe55b7 | 57 | typedef enum |
jksoft | 0:8c643bfe55b7 | 58 | { |
jksoft | 0:8c643bfe55b7 | 59 | NRF_GPIO_PIN_NOPULL = GPIO_PIN_CNF_PULL_Disabled, ///< Pin pullup resistor disabled |
jksoft | 0:8c643bfe55b7 | 60 | NRF_GPIO_PIN_PULLDOWN = GPIO_PIN_CNF_PULL_Pulldown, ///< Pin pulldown resistor enabled |
jksoft | 0:8c643bfe55b7 | 61 | NRF_GPIO_PIN_PULLUP = GPIO_PIN_CNF_PULL_Pullup, ///< Pin pullup resistor enabled |
jksoft | 0:8c643bfe55b7 | 62 | } nrf_gpio_pin_pull_t; |
jksoft | 0:8c643bfe55b7 | 63 | |
jksoft | 0:8c643bfe55b7 | 64 | /** |
jksoft | 0:8c643bfe55b7 | 65 | * @enum nrf_gpio_pin_sense_t |
jksoft | 0:8c643bfe55b7 | 66 | * @brief Enumerator used for selecting the pin to sense high or low level on the pin input. |
jksoft | 0:8c643bfe55b7 | 67 | */ |
jksoft | 0:8c643bfe55b7 | 68 | typedef enum |
jksoft | 0:8c643bfe55b7 | 69 | { |
jksoft | 0:8c643bfe55b7 | 70 | NRF_GPIO_PIN_NOSENSE = GPIO_PIN_CNF_SENSE_Disabled, ///< Pin sense level disabled. |
jksoft | 0:8c643bfe55b7 | 71 | NRF_GPIO_PIN_SENSE_LOW = GPIO_PIN_CNF_SENSE_Low, ///< Pin sense low level. |
jksoft | 0:8c643bfe55b7 | 72 | NRF_GPIO_PIN_SENSE_HIGH = GPIO_PIN_CNF_SENSE_High, ///< Pin sense high level. |
jksoft | 0:8c643bfe55b7 | 73 | } nrf_gpio_pin_sense_t; |
jksoft | 0:8c643bfe55b7 | 74 | |
jksoft | 0:8c643bfe55b7 | 75 | /** |
jksoft | 0:8c643bfe55b7 | 76 | * @brief Function for configuring the GPIO pin range as outputs with normal drive strength. |
jksoft | 0:8c643bfe55b7 | 77 | * This function can be used to configure pin range as simple output with gate driving GPIO_PIN_CNF_DRIVE_S0S1 (normal cases). |
jksoft | 0:8c643bfe55b7 | 78 | * |
jksoft | 0:8c643bfe55b7 | 79 | * @param pin_range_start specifies the start number (inclusive) in the range of pin numbers to be configured (allowed values 0-30) |
jksoft | 0:8c643bfe55b7 | 80 | * |
jksoft | 0:8c643bfe55b7 | 81 | * @param pin_range_end specifies the end number (inclusive) in the range of pin numbers to be configured (allowed values 0-30) |
jksoft | 0:8c643bfe55b7 | 82 | * |
jksoft | 0:8c643bfe55b7 | 83 | * @note For configuring only one pin as output use @ref nrf_gpio_cfg_output |
jksoft | 0:8c643bfe55b7 | 84 | * Sense capability on the pin is disabled, and input is disconnected from the buffer as the pins are configured as output. |
jksoft | 0:8c643bfe55b7 | 85 | */ |
jksoft | 0:8c643bfe55b7 | 86 | static __INLINE void nrf_gpio_range_cfg_output(uint32_t pin_range_start, uint32_t pin_range_end) |
jksoft | 0:8c643bfe55b7 | 87 | { |
jksoft | 0:8c643bfe55b7 | 88 | /*lint -e{845} // A zero has been given as right argument to operator '|'" */ |
jksoft | 0:8c643bfe55b7 | 89 | for (; pin_range_start <= pin_range_end; pin_range_start++) |
jksoft | 0:8c643bfe55b7 | 90 | { |
jksoft | 0:8c643bfe55b7 | 91 | NRF_GPIO->PIN_CNF[pin_range_start] = (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos) |
jksoft | 0:8c643bfe55b7 | 92 | | (GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos) |
jksoft | 0:8c643bfe55b7 | 93 | | (GPIO_PIN_CNF_PULL_Disabled << GPIO_PIN_CNF_PULL_Pos) |
jksoft | 0:8c643bfe55b7 | 94 | | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) |
jksoft | 0:8c643bfe55b7 | 95 | | (GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos); |
jksoft | 0:8c643bfe55b7 | 96 | } |
jksoft | 0:8c643bfe55b7 | 97 | } |
jksoft | 0:8c643bfe55b7 | 98 | |
jksoft | 0:8c643bfe55b7 | 99 | /** |
jksoft | 0:8c643bfe55b7 | 100 | * @brief Function for configuring the GPIO pin range as inputs with given initial value set, hiding inner details. |
jksoft | 0:8c643bfe55b7 | 101 | * This function can be used to configure pin range as simple input. |
jksoft | 0:8c643bfe55b7 | 102 | * |
jksoft | 0:8c643bfe55b7 | 103 | * @param pin_range_start specifies the start number (inclusive) in the range of pin numbers to be configured (allowed values 0-30) |
jksoft | 0:8c643bfe55b7 | 104 | * |
jksoft | 0:8c643bfe55b7 | 105 | * @param pin_range_end specifies the end number (inclusive) in the range of pin numbers to be configured (allowed values 0-30) |
jksoft | 0:8c643bfe55b7 | 106 | * |
jksoft | 0:8c643bfe55b7 | 107 | * @param pull_config State of the pin range pull resistor (no pull, pulled down or pulled high) |
jksoft | 0:8c643bfe55b7 | 108 | * |
jksoft | 0:8c643bfe55b7 | 109 | * @note For configuring only one pin as input use @ref nrf_gpio_cfg_input |
jksoft | 0:8c643bfe55b7 | 110 | * Sense capability on the pin is disabled, and input is connected to buffer so that the GPIO->IN register is readable |
jksoft | 0:8c643bfe55b7 | 111 | */ |
jksoft | 0:8c643bfe55b7 | 112 | static __INLINE void nrf_gpio_range_cfg_input(uint32_t pin_range_start, uint32_t pin_range_end, nrf_gpio_pin_pull_t pull_config) |
jksoft | 0:8c643bfe55b7 | 113 | { |
jksoft | 0:8c643bfe55b7 | 114 | /*lint -e{845} // A zero has been given as right argument to operator '|'" */ |
jksoft | 0:8c643bfe55b7 | 115 | for (; pin_range_start <= pin_range_end; pin_range_start++) |
jksoft | 0:8c643bfe55b7 | 116 | { |
jksoft | 0:8c643bfe55b7 | 117 | NRF_GPIO->PIN_CNF[pin_range_start] = (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos) |
jksoft | 0:8c643bfe55b7 | 118 | | (GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos) |
jksoft | 0:8c643bfe55b7 | 119 | | (pull_config << GPIO_PIN_CNF_PULL_Pos) |
jksoft | 0:8c643bfe55b7 | 120 | | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) |
jksoft | 0:8c643bfe55b7 | 121 | | (GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos); |
jksoft | 0:8c643bfe55b7 | 122 | } |
jksoft | 0:8c643bfe55b7 | 123 | } |
jksoft | 0:8c643bfe55b7 | 124 | |
jksoft | 0:8c643bfe55b7 | 125 | /** |
jksoft | 0:8c643bfe55b7 | 126 | * @brief Function for configuring the given GPIO pin number as output with given initial value set, hiding inner details. |
jksoft | 0:8c643bfe55b7 | 127 | * This function can be used to configure pin range as simple input with gate driving GPIO_PIN_CNF_DRIVE_S0S1 (normal cases). |
jksoft | 0:8c643bfe55b7 | 128 | * |
jksoft | 0:8c643bfe55b7 | 129 | * @param pin_number specifies the pin number of gpio pin numbers to be configured (allowed values 0-30) |
jksoft | 0:8c643bfe55b7 | 130 | * |
jksoft | 0:8c643bfe55b7 | 131 | * @note Sense capability on the pin is disabled, and input is disconnected from the buffer as the pins are configured as output. |
jksoft | 0:8c643bfe55b7 | 132 | */ |
jksoft | 0:8c643bfe55b7 | 133 | static __INLINE void nrf_gpio_cfg_output(uint32_t pin_number) |
jksoft | 0:8c643bfe55b7 | 134 | { |
jksoft | 0:8c643bfe55b7 | 135 | /*lint -e{845} // A zero has been given as right argument to operator '|'" */ |
jksoft | 0:8c643bfe55b7 | 136 | NRF_GPIO->PIN_CNF[pin_number] = (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos) |
jksoft | 0:8c643bfe55b7 | 137 | | (GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos) |
jksoft | 0:8c643bfe55b7 | 138 | | (GPIO_PIN_CNF_PULL_Disabled << GPIO_PIN_CNF_PULL_Pos) |
jksoft | 0:8c643bfe55b7 | 139 | | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) |
jksoft | 0:8c643bfe55b7 | 140 | | (GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos); |
jksoft | 0:8c643bfe55b7 | 141 | } |
jksoft | 0:8c643bfe55b7 | 142 | |
jksoft | 0:8c643bfe55b7 | 143 | /** |
jksoft | 0:8c643bfe55b7 | 144 | * @brief Function for configuring the given GPIO pin number as input with given initial value set, hiding inner details. |
jksoft | 0:8c643bfe55b7 | 145 | * This function can be used to configure pin range as simple input with gate driving GPIO_PIN_CNF_DRIVE_S0S1 (normal cases). |
jksoft | 0:8c643bfe55b7 | 146 | * |
jksoft | 0:8c643bfe55b7 | 147 | * @param pin_number specifies the pin number of gpio pin numbers to be configured (allowed values 0-30) |
jksoft | 0:8c643bfe55b7 | 148 | * |
jksoft | 0:8c643bfe55b7 | 149 | * @param pull_config State of the pin range pull resistor (no pull, pulled down or pulled high) |
jksoft | 0:8c643bfe55b7 | 150 | * |
jksoft | 0:8c643bfe55b7 | 151 | * @note Sense capability on the pin is disabled, and input is connected to buffer so that the GPIO->IN register is readable |
jksoft | 0:8c643bfe55b7 | 152 | */ |
jksoft | 0:8c643bfe55b7 | 153 | static __INLINE void nrf_gpio_cfg_input(uint32_t pin_number, nrf_gpio_pin_pull_t pull_config) |
jksoft | 0:8c643bfe55b7 | 154 | { |
jksoft | 0:8c643bfe55b7 | 155 | /*lint -e{845} // A zero has been given as right argument to operator '|'" */ |
jksoft | 0:8c643bfe55b7 | 156 | NRF_GPIO->PIN_CNF[pin_number] = (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos) |
jksoft | 0:8c643bfe55b7 | 157 | | (GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos) |
jksoft | 0:8c643bfe55b7 | 158 | | (pull_config << GPIO_PIN_CNF_PULL_Pos) |
jksoft | 0:8c643bfe55b7 | 159 | | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) |
jksoft | 0:8c643bfe55b7 | 160 | | (GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos); |
jksoft | 0:8c643bfe55b7 | 161 | } |
jksoft | 0:8c643bfe55b7 | 162 | |
jksoft | 0:8c643bfe55b7 | 163 | /** |
jksoft | 0:8c643bfe55b7 | 164 | * @brief Function for configuring the given GPIO pin number as input with given initial value set, hiding inner details. |
jksoft | 0:8c643bfe55b7 | 165 | * This function can be used to configure pin range as simple input with gate driving GPIO_PIN_CNF_DRIVE_S0S1 (normal cases). |
jksoft | 0:8c643bfe55b7 | 166 | * Sense capability on the pin is configurable, and input is connected to buffer so that the GPIO->IN register is readable. |
jksoft | 0:8c643bfe55b7 | 167 | * |
jksoft | 0:8c643bfe55b7 | 168 | * @param pin_number specifies the pin number of gpio pin numbers to be configured (allowed values 0-30). |
jksoft | 0:8c643bfe55b7 | 169 | * |
jksoft | 0:8c643bfe55b7 | 170 | * @param pull_config state of the pin pull resistor (no pull, pulled down or pulled high). |
jksoft | 0:8c643bfe55b7 | 171 | * |
jksoft | 0:8c643bfe55b7 | 172 | * @param sense_config sense level of the pin (no sense, sense low or sense high). |
jksoft | 0:8c643bfe55b7 | 173 | */ |
jksoft | 0:8c643bfe55b7 | 174 | static __INLINE void nrf_gpio_cfg_sense_input(uint32_t pin_number, nrf_gpio_pin_pull_t pull_config, nrf_gpio_pin_sense_t sense_config) |
jksoft | 0:8c643bfe55b7 | 175 | { |
jksoft | 0:8c643bfe55b7 | 176 | /*lint -e{845} // A zero has been given as right argument to operator '|'" */ |
jksoft | 0:8c643bfe55b7 | 177 | NRF_GPIO->PIN_CNF[pin_number] = (sense_config << GPIO_PIN_CNF_SENSE_Pos) |
jksoft | 0:8c643bfe55b7 | 178 | | (GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos) |
jksoft | 0:8c643bfe55b7 | 179 | | (pull_config << GPIO_PIN_CNF_PULL_Pos) |
jksoft | 0:8c643bfe55b7 | 180 | | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) |
jksoft | 0:8c643bfe55b7 | 181 | | (GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos); |
jksoft | 0:8c643bfe55b7 | 182 | } |
jksoft | 0:8c643bfe55b7 | 183 | |
jksoft | 0:8c643bfe55b7 | 184 | /** |
jksoft | 0:8c643bfe55b7 | 185 | * @brief Function for setting the direction for a GPIO pin. |
jksoft | 0:8c643bfe55b7 | 186 | * |
jksoft | 0:8c643bfe55b7 | 187 | * @param pin_number specifies the pin number [0:31] for which to |
jksoft | 0:8c643bfe55b7 | 188 | * set the direction. |
jksoft | 0:8c643bfe55b7 | 189 | * |
jksoft | 0:8c643bfe55b7 | 190 | * @param direction specifies the direction |
jksoft | 0:8c643bfe55b7 | 191 | */ |
jksoft | 0:8c643bfe55b7 | 192 | static __INLINE void nrf_gpio_pin_dir_set(uint32_t pin_number, nrf_gpio_pin_dir_t direction) |
jksoft | 0:8c643bfe55b7 | 193 | { |
jksoft | 0:8c643bfe55b7 | 194 | if(direction == NRF_GPIO_PIN_DIR_INPUT) |
jksoft | 0:8c643bfe55b7 | 195 | { |
jksoft | 0:8c643bfe55b7 | 196 | NRF_GPIO->PIN_CNF[pin_number] = |
jksoft | 0:8c643bfe55b7 | 197 | (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos) |
jksoft | 0:8c643bfe55b7 | 198 | | (GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos) |
jksoft | 0:8c643bfe55b7 | 199 | | (GPIO_PIN_CNF_PULL_Disabled << GPIO_PIN_CNF_PULL_Pos) |
jksoft | 0:8c643bfe55b7 | 200 | | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) |
jksoft | 0:8c643bfe55b7 | 201 | | (GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos); |
jksoft | 0:8c643bfe55b7 | 202 | } |
jksoft | 0:8c643bfe55b7 | 203 | else |
jksoft | 0:8c643bfe55b7 | 204 | { |
jksoft | 0:8c643bfe55b7 | 205 | NRF_GPIO->DIRSET = (1UL << pin_number); |
jksoft | 0:8c643bfe55b7 | 206 | } |
jksoft | 0:8c643bfe55b7 | 207 | } |
jksoft | 0:8c643bfe55b7 | 208 | |
jksoft | 0:8c643bfe55b7 | 209 | /** |
jksoft | 0:8c643bfe55b7 | 210 | * @brief Function for setting a GPIO pin. |
jksoft | 0:8c643bfe55b7 | 211 | * |
jksoft | 0:8c643bfe55b7 | 212 | * Note that the pin must be configured as an output for this |
jksoft | 0:8c643bfe55b7 | 213 | * function to have any effect. |
jksoft | 0:8c643bfe55b7 | 214 | * |
jksoft | 0:8c643bfe55b7 | 215 | * @param pin_number specifies the pin number [0:31] to |
jksoft | 0:8c643bfe55b7 | 216 | * set. |
jksoft | 0:8c643bfe55b7 | 217 | */ |
jksoft | 0:8c643bfe55b7 | 218 | static __INLINE void nrf_gpio_pin_set(uint32_t pin_number) |
jksoft | 0:8c643bfe55b7 | 219 | { |
jksoft | 0:8c643bfe55b7 | 220 | NRF_GPIO->OUTSET = (1UL << pin_number); |
jksoft | 0:8c643bfe55b7 | 221 | } |
jksoft | 0:8c643bfe55b7 | 222 | |
jksoft | 0:8c643bfe55b7 | 223 | /** |
jksoft | 0:8c643bfe55b7 | 224 | * @brief Function for clearing a GPIO pin. |
jksoft | 0:8c643bfe55b7 | 225 | * |
jksoft | 0:8c643bfe55b7 | 226 | * Note that the pin must be configured as an output for this |
jksoft | 0:8c643bfe55b7 | 227 | * function to have any effect. |
jksoft | 0:8c643bfe55b7 | 228 | * |
jksoft | 0:8c643bfe55b7 | 229 | * @param pin_number specifies the pin number [0:31] to |
jksoft | 0:8c643bfe55b7 | 230 | * clear. |
jksoft | 0:8c643bfe55b7 | 231 | */ |
jksoft | 0:8c643bfe55b7 | 232 | static __INLINE void nrf_gpio_pin_clear(uint32_t pin_number) |
jksoft | 0:8c643bfe55b7 | 233 | { |
jksoft | 0:8c643bfe55b7 | 234 | NRF_GPIO->OUTCLR = (1UL << pin_number); |
jksoft | 0:8c643bfe55b7 | 235 | } |
jksoft | 0:8c643bfe55b7 | 236 | |
jksoft | 0:8c643bfe55b7 | 237 | /** |
jksoft | 0:8c643bfe55b7 | 238 | * @brief Function for toggling a GPIO pin. |
jksoft | 0:8c643bfe55b7 | 239 | * |
jksoft | 0:8c643bfe55b7 | 240 | * Note that the pin must be configured as an output for this |
jksoft | 0:8c643bfe55b7 | 241 | * function to have any effect. |
jksoft | 0:8c643bfe55b7 | 242 | * |
jksoft | 0:8c643bfe55b7 | 243 | * @param pin_number specifies the pin number [0:31] to |
jksoft | 0:8c643bfe55b7 | 244 | * toggle. |
jksoft | 0:8c643bfe55b7 | 245 | */ |
jksoft | 0:8c643bfe55b7 | 246 | static __INLINE void nrf_gpio_pin_toggle(uint32_t pin_number) |
jksoft | 0:8c643bfe55b7 | 247 | { |
jksoft | 0:8c643bfe55b7 | 248 | NRF_GPIO->OUT ^= (1UL << pin_number); |
jksoft | 0:8c643bfe55b7 | 249 | } |
jksoft | 0:8c643bfe55b7 | 250 | |
jksoft | 0:8c643bfe55b7 | 251 | /** |
jksoft | 0:8c643bfe55b7 | 252 | * @brief Function for writing a value to a GPIO pin. |
jksoft | 0:8c643bfe55b7 | 253 | * |
jksoft | 0:8c643bfe55b7 | 254 | * Note that the pin must be configured as an output for this |
jksoft | 0:8c643bfe55b7 | 255 | * function to have any effect. |
jksoft | 0:8c643bfe55b7 | 256 | * |
jksoft | 0:8c643bfe55b7 | 257 | * @param pin_number specifies the pin number [0:31] to |
jksoft | 0:8c643bfe55b7 | 258 | * write. |
jksoft | 0:8c643bfe55b7 | 259 | * |
jksoft | 0:8c643bfe55b7 | 260 | * @param value specifies the value to be written to the pin. |
jksoft | 0:8c643bfe55b7 | 261 | * @arg 0 clears the pin |
jksoft | 0:8c643bfe55b7 | 262 | * @arg >=1 sets the pin. |
jksoft | 0:8c643bfe55b7 | 263 | */ |
jksoft | 0:8c643bfe55b7 | 264 | static __INLINE void nrf_gpio_pin_write(uint32_t pin_number, uint32_t value) |
jksoft | 0:8c643bfe55b7 | 265 | { |
jksoft | 0:8c643bfe55b7 | 266 | if (value == 0) |
jksoft | 0:8c643bfe55b7 | 267 | { |
jksoft | 0:8c643bfe55b7 | 268 | nrf_gpio_pin_clear(pin_number); |
jksoft | 0:8c643bfe55b7 | 269 | } |
jksoft | 0:8c643bfe55b7 | 270 | else |
jksoft | 0:8c643bfe55b7 | 271 | { |
jksoft | 0:8c643bfe55b7 | 272 | nrf_gpio_pin_set(pin_number); |
jksoft | 0:8c643bfe55b7 | 273 | } |
jksoft | 0:8c643bfe55b7 | 274 | } |
jksoft | 0:8c643bfe55b7 | 275 | |
jksoft | 0:8c643bfe55b7 | 276 | /** |
jksoft | 0:8c643bfe55b7 | 277 | * @brief Function for reading the input level of a GPIO pin. |
jksoft | 0:8c643bfe55b7 | 278 | * |
jksoft | 0:8c643bfe55b7 | 279 | * Note that the pin must have input connected for the value |
jksoft | 0:8c643bfe55b7 | 280 | * returned from this function to be valid. |
jksoft | 0:8c643bfe55b7 | 281 | * |
jksoft | 0:8c643bfe55b7 | 282 | * @param pin_number specifies the pin number [0:31] to |
jksoft | 0:8c643bfe55b7 | 283 | * read. |
jksoft | 0:8c643bfe55b7 | 284 | * |
jksoft | 0:8c643bfe55b7 | 285 | * @return |
jksoft | 0:8c643bfe55b7 | 286 | * @retval 0 if the pin input level is low. |
jksoft | 0:8c643bfe55b7 | 287 | * @retval 1 if the pin input level is high. |
jksoft | 0:8c643bfe55b7 | 288 | * @retval > 1 should never occur. |
jksoft | 0:8c643bfe55b7 | 289 | */ |
jksoft | 0:8c643bfe55b7 | 290 | static __INLINE uint32_t nrf_gpio_pin_read(uint32_t pin_number) |
jksoft | 0:8c643bfe55b7 | 291 | { |
jksoft | 0:8c643bfe55b7 | 292 | return ((NRF_GPIO->IN >> pin_number) & 1UL); |
jksoft | 0:8c643bfe55b7 | 293 | } |
jksoft | 0:8c643bfe55b7 | 294 | |
jksoft | 0:8c643bfe55b7 | 295 | /** |
jksoft | 0:8c643bfe55b7 | 296 | * @brief Generic function for writing a single byte of a 32 bit word at a given |
jksoft | 0:8c643bfe55b7 | 297 | * address. |
jksoft | 0:8c643bfe55b7 | 298 | * |
jksoft | 0:8c643bfe55b7 | 299 | * This function should not be called from outside the nrf_gpio |
jksoft | 0:8c643bfe55b7 | 300 | * abstraction layer. |
jksoft | 0:8c643bfe55b7 | 301 | * |
jksoft | 0:8c643bfe55b7 | 302 | * @param word_address is the address of the word to be written. |
jksoft | 0:8c643bfe55b7 | 303 | * |
jksoft | 0:8c643bfe55b7 | 304 | * @param byte_no is the the word byte number (0-3) to be written. |
jksoft | 0:8c643bfe55b7 | 305 | * |
jksoft | 0:8c643bfe55b7 | 306 | * @param value is the value to be written to byte "byte_no" of word |
jksoft | 0:8c643bfe55b7 | 307 | * at address "word_address" |
jksoft | 0:8c643bfe55b7 | 308 | */ |
jksoft | 0:8c643bfe55b7 | 309 | static __INLINE void nrf_gpio_word_byte_write(volatile uint32_t * word_address, uint8_t byte_no, uint8_t value) |
jksoft | 0:8c643bfe55b7 | 310 | { |
jksoft | 0:8c643bfe55b7 | 311 | *((volatile uint8_t*)(word_address) + byte_no) = value; |
jksoft | 0:8c643bfe55b7 | 312 | } |
jksoft | 0:8c643bfe55b7 | 313 | |
jksoft | 0:8c643bfe55b7 | 314 | /** |
jksoft | 0:8c643bfe55b7 | 315 | * @brief Generic function for reading a single byte of a 32 bit word at a given |
jksoft | 0:8c643bfe55b7 | 316 | * address. |
jksoft | 0:8c643bfe55b7 | 317 | * |
jksoft | 0:8c643bfe55b7 | 318 | * This function should not be called from outside the nrf_gpio |
jksoft | 0:8c643bfe55b7 | 319 | * abstraction layer. |
jksoft | 0:8c643bfe55b7 | 320 | * |
jksoft | 0:8c643bfe55b7 | 321 | * @param word_address is the address of the word to be read. |
jksoft | 0:8c643bfe55b7 | 322 | * |
jksoft | 0:8c643bfe55b7 | 323 | * @param byte_no is the the byte number (0-3) of the word to be read. |
jksoft | 0:8c643bfe55b7 | 324 | * |
jksoft | 0:8c643bfe55b7 | 325 | * @return byte "byte_no" of word at address "word_address". |
jksoft | 0:8c643bfe55b7 | 326 | */ |
jksoft | 0:8c643bfe55b7 | 327 | static __INLINE uint8_t nrf_gpio_word_byte_read(const volatile uint32_t* word_address, uint8_t byte_no) |
jksoft | 0:8c643bfe55b7 | 328 | { |
jksoft | 0:8c643bfe55b7 | 329 | return (*((const volatile uint8_t*)(word_address) + byte_no)); |
jksoft | 0:8c643bfe55b7 | 330 | } |
jksoft | 0:8c643bfe55b7 | 331 | |
jksoft | 0:8c643bfe55b7 | 332 | /** |
jksoft | 0:8c643bfe55b7 | 333 | * @brief Function for setting the direction of a port. |
jksoft | 0:8c643bfe55b7 | 334 | * |
jksoft | 0:8c643bfe55b7 | 335 | * @param port is the port for which to set the direction. |
jksoft | 0:8c643bfe55b7 | 336 | * |
jksoft | 0:8c643bfe55b7 | 337 | * @param dir direction to be set for this port. |
jksoft | 0:8c643bfe55b7 | 338 | */ |
jksoft | 0:8c643bfe55b7 | 339 | static __INLINE void nrf_gpio_port_dir_set(nrf_gpio_port_select_t port, nrf_gpio_port_dir_t dir) |
jksoft | 0:8c643bfe55b7 | 340 | { |
jksoft | 0:8c643bfe55b7 | 341 | if (dir == NRF_GPIO_PORT_DIR_OUTPUT) |
jksoft | 0:8c643bfe55b7 | 342 | { |
jksoft | 0:8c643bfe55b7 | 343 | nrf_gpio_word_byte_write(&NRF_GPIO->DIRSET, port, 0xFF); |
jksoft | 0:8c643bfe55b7 | 344 | } |
jksoft | 0:8c643bfe55b7 | 345 | else |
jksoft | 0:8c643bfe55b7 | 346 | { |
jksoft | 0:8c643bfe55b7 | 347 | nrf_gpio_range_cfg_input(port*8, (port+1)*8-1, NRF_GPIO_PIN_NOPULL); |
jksoft | 0:8c643bfe55b7 | 348 | } |
jksoft | 0:8c643bfe55b7 | 349 | } |
jksoft | 0:8c643bfe55b7 | 350 | |
jksoft | 0:8c643bfe55b7 | 351 | /** |
jksoft | 0:8c643bfe55b7 | 352 | * @brief Function for reading a GPIO port. |
jksoft | 0:8c643bfe55b7 | 353 | * |
jksoft | 0:8c643bfe55b7 | 354 | * @param port is the port to read. |
jksoft | 0:8c643bfe55b7 | 355 | * |
jksoft | 0:8c643bfe55b7 | 356 | * @return the input value on this port. |
jksoft | 0:8c643bfe55b7 | 357 | */ |
jksoft | 0:8c643bfe55b7 | 358 | static __INLINE uint8_t nrf_gpio_port_read(nrf_gpio_port_select_t port) |
jksoft | 0:8c643bfe55b7 | 359 | { |
jksoft | 0:8c643bfe55b7 | 360 | return nrf_gpio_word_byte_read(&NRF_GPIO->IN, port); |
jksoft | 0:8c643bfe55b7 | 361 | } |
jksoft | 0:8c643bfe55b7 | 362 | |
jksoft | 0:8c643bfe55b7 | 363 | /** |
jksoft | 0:8c643bfe55b7 | 364 | * @brief Function for writing to a GPIO port. |
jksoft | 0:8c643bfe55b7 | 365 | * |
jksoft | 0:8c643bfe55b7 | 366 | * @param port is the port to write. |
jksoft | 0:8c643bfe55b7 | 367 | * |
jksoft | 0:8c643bfe55b7 | 368 | * @param value is the value to write to this port. |
jksoft | 0:8c643bfe55b7 | 369 | * |
jksoft | 0:8c643bfe55b7 | 370 | * @sa nrf_gpio_port_dir_set() |
jksoft | 0:8c643bfe55b7 | 371 | */ |
jksoft | 0:8c643bfe55b7 | 372 | static __INLINE void nrf_gpio_port_write(nrf_gpio_port_select_t port, uint8_t value) |
jksoft | 0:8c643bfe55b7 | 373 | { |
jksoft | 0:8c643bfe55b7 | 374 | nrf_gpio_word_byte_write(&NRF_GPIO->OUT, port, value); |
jksoft | 0:8c643bfe55b7 | 375 | } |
jksoft | 0:8c643bfe55b7 | 376 | |
jksoft | 0:8c643bfe55b7 | 377 | /** |
jksoft | 0:8c643bfe55b7 | 378 | * @brief Function for setting individual pins on GPIO port. |
jksoft | 0:8c643bfe55b7 | 379 | * |
jksoft | 0:8c643bfe55b7 | 380 | * @param port is the port for which to set the pins. |
jksoft | 0:8c643bfe55b7 | 381 | * |
jksoft | 0:8c643bfe55b7 | 382 | * @param set_mask is a mask specifying which pins to set. A bit |
jksoft | 0:8c643bfe55b7 | 383 | * set to 1 indicates that the corresponding port pin shall be |
jksoft | 0:8c643bfe55b7 | 384 | * set. |
jksoft | 0:8c643bfe55b7 | 385 | * |
jksoft | 0:8c643bfe55b7 | 386 | * @sa nrf_gpio_port_dir_set() |
jksoft | 0:8c643bfe55b7 | 387 | */ |
jksoft | 0:8c643bfe55b7 | 388 | static __INLINE void nrf_gpio_port_set(nrf_gpio_port_select_t port, uint8_t set_mask) |
jksoft | 0:8c643bfe55b7 | 389 | { |
jksoft | 0:8c643bfe55b7 | 390 | nrf_gpio_word_byte_write(&NRF_GPIO->OUTSET, port, set_mask); |
jksoft | 0:8c643bfe55b7 | 391 | } |
jksoft | 0:8c643bfe55b7 | 392 | |
jksoft | 0:8c643bfe55b7 | 393 | /** |
jksoft | 0:8c643bfe55b7 | 394 | * @brief Function for clearing individual pins on GPIO port. |
jksoft | 0:8c643bfe55b7 | 395 | * |
jksoft | 0:8c643bfe55b7 | 396 | * @param port is the port for which to clear the pins. |
jksoft | 0:8c643bfe55b7 | 397 | * |
jksoft | 0:8c643bfe55b7 | 398 | * @param clr_mask is a mask specifying which pins to clear. A bit |
jksoft | 0:8c643bfe55b7 | 399 | * set to 1 indicates that the corresponding port pin shall be |
jksoft | 0:8c643bfe55b7 | 400 | * cleared. |
jksoft | 0:8c643bfe55b7 | 401 | * |
jksoft | 0:8c643bfe55b7 | 402 | * @sa nrf_gpio_port_dir_set() |
jksoft | 0:8c643bfe55b7 | 403 | */ |
jksoft | 0:8c643bfe55b7 | 404 | static __INLINE void nrf_gpio_port_clear(nrf_gpio_port_select_t port, uint8_t clr_mask) |
jksoft | 0:8c643bfe55b7 | 405 | { |
jksoft | 0:8c643bfe55b7 | 406 | nrf_gpio_word_byte_write(&NRF_GPIO->OUTCLR, port, clr_mask); |
jksoft | 0:8c643bfe55b7 | 407 | } |
jksoft | 0:8c643bfe55b7 | 408 | |
jksoft | 0:8c643bfe55b7 | 409 | /** @} */ |
jksoft | 0:8c643bfe55b7 | 410 | |
jksoft | 0:8c643bfe55b7 | 411 | #endif |