19 #ifndef CODEBASE_HAL_HAL_GPIO_H_ 20 #define CODEBASE_HAL_HAL_GPIO_H_ 54 static inline void hal_gpio_cfg( uint32_t pin_num,
67 static inline void hal_gpio_cfg_output(uint32_t pin_num, uint32_t init_val);
75 static inline void hal_gpio_cfg_high_output(uint32_t pin_num, uint32_t init_val);
83 static inline void hal_gpio_cfg_input(uint32_t pin_num,
hal_gpio_pull_t pull_config);
90 static inline void hal_gpio_pin_write(uint32_t pin_num, uint32_t val);
96 static inline void hal_gpio_pin_set(uint32_t pin_num);
102 static inline void hal_gpio_pin_clear(uint32_t pin_num);
108 static inline void hal_gpio_pin_toggle(uint32_t pin_num);
116 static inline uint32_t hal_gpio_pin_read(uint32_t pin_num);
118 static inline void hal_gpio_cfg(uint32_t pin_num, uint32_t dir, uint32_t input, uint32_t pull,
119 uint32_t drive, uint32_t sense)
121 NRF_GPIO->PIN_CNF[pin_num] = (dir << GPIO_PIN_CNF_DIR_Pos) | (input << GPIO_PIN_CNF_INPUT_Pos)
122 | (pull << GPIO_PIN_CNF_PULL_Pos) | (drive << GPIO_PIN_CNF_DRIVE_Pos)
123 | (sense << GPIO_PIN_CNF_SENSE_Pos);
126 static inline void hal_gpio_cfg_output(uint32_t pin_num, uint32_t init_val)
128 hal_gpio_cfg(pin_num,
129 GPIO_PIN_CNF_DIR_Input,
130 GPIO_PIN_CNF_INPUT_Disconnect,
131 GPIO_PIN_CNF_PULL_Disabled,
132 GPIO_PIN_CNF_DRIVE_S0S1,
133 GPIO_PIN_CNF_SENSE_Disabled);
134 hal_gpio_pin_write(pin_num, init_val);
135 hal_gpio_cfg(pin_num,
136 GPIO_PIN_CNF_DIR_Output,
137 GPIO_PIN_CNF_INPUT_Disconnect,
138 GPIO_PIN_CNF_PULL_Disabled,
139 GPIO_PIN_CNF_DRIVE_S0S1,
140 GPIO_PIN_CNF_SENSE_Disabled);
143 static inline void hal_gpio_cfg_high_output(uint32_t pin_num, uint32_t init_val)
145 hal_gpio_cfg(pin_num,
146 GPIO_PIN_CNF_DIR_Input,
147 GPIO_PIN_CNF_INPUT_Disconnect,
148 GPIO_PIN_CNF_PULL_Disabled,
149 GPIO_PIN_CNF_DRIVE_S0S1,
150 GPIO_PIN_CNF_SENSE_Disabled);
151 hal_gpio_pin_write(pin_num, init_val);
152 hal_gpio_cfg(pin_num,
153 GPIO_PIN_CNF_DIR_Output,
154 GPIO_PIN_CNF_INPUT_Disconnect,
155 GPIO_PIN_CNF_PULL_Disabled,
156 GPIO_PIN_CNF_DRIVE_H0H1,
157 GPIO_PIN_CNF_SENSE_Disabled);
160 static inline void hal_gpio_cfg_input(uint32_t pin_num,
hal_gpio_pull_t pull_config)
162 hal_gpio_cfg(pin_num,
163 GPIO_PIN_CNF_DIR_Input,
164 GPIO_PIN_CNF_INPUT_Connect, pull_config,
165 GPIO_PIN_CNF_DRIVE_S0S1,
166 GPIO_PIN_CNF_SENSE_Disabled);
169 static inline void hal_gpio_pin_write(uint32_t pin_num, uint32_t val)
173 hal_gpio_pin_set(pin_num);
177 hal_gpio_pin_clear(pin_num);
181 static inline void hal_gpio_pin_set(uint32_t pin_num)
183 NRF_GPIO->OUTSET = (1UL << pin_num);
186 static inline void hal_gpio_pin_clear(uint32_t pin_num)
188 NRF_GPIO->OUTCLR = (1UL << pin_num);
191 static inline void hal_gpio_pin_toggle(uint32_t pin_num)
193 const uint32_t pin_bit = 1UL << pin_num;
194 const uint32_t pin_state = (NRF_GPIO->OUT & pin_bit);
199 NRF_GPIO->OUTSET = pin_bit;
204 NRF_GPIO->OUTCLR = pin_bit;
208 static inline uint32_t hal_gpio_pin_read(uint32_t pin_num)
210 return ((NRF_GPIO->IN >> pin_num) & 1UL);