10 "This implementation assumes that the number of pins is less "
11 "than or equal to 32");
18 static uint32_t index_to_mask(uint32_t index) {
return 1u << index; }
45 ptrdiff_t reg_lower_offset,
46 ptrdiff_t reg_upper_offset, uint32_t mask,
52 const uint32_t mask_lower_half = mask & 0x0000FFFFu;
53 const uint32_t mask_upper_half = mask & 0xFFFF0000u;
54 if (mask_lower_half != 0) {
55 mmio_region_write32(gpio->
base_addr, reg_lower_offset,
56 (mask_lower_half << 16) | (val & 0x0000FFFFu));
58 if (mask_upper_half != 0) {
59 mmio_region_write32(gpio->
base_addr, reg_upper_offset,
60 mask_upper_half | ((val & 0xFFFF0000u) >> 16));
87 ptrdiff_t reg_lower_offset,
88 ptrdiff_t reg_upper_offset,
89 uint32_t index,
bool val) {
96 const ptrdiff_t offset = (index < 16) ? reg_lower_offset : reg_upper_offset;
99 const uint32_t mask = index_to_mask(index % 16);
100 mmio_region_write32(gpio->
base_addr, offset,
101 (mask << 16) | (val ? mask : 0u));
113 mmio_region_write32(gpio->
base_addr, GPIO_INTR_ENABLE_REG_OFFSET, 0);
114 mmio_region_write32(gpio->
base_addr, GPIO_DIRECT_OE_REG_OFFSET, 0);
115 mmio_region_write32(gpio->
base_addr, GPIO_DIRECT_OUT_REG_OFFSET, 0);
116 mmio_region_write32(gpio->
base_addr, GPIO_INTR_CTRL_EN_RISING_REG_OFFSET, 0);
117 mmio_region_write32(gpio->
base_addr, GPIO_INTR_CTRL_EN_FALLING_REG_OFFSET, 0);
118 mmio_region_write32(gpio->
base_addr, GPIO_INTR_CTRL_EN_LVLHIGH_REG_OFFSET, 0);
119 mmio_region_write32(gpio->
base_addr, GPIO_INTR_CTRL_EN_LVLLOW_REG_OFFSET, 0);
120 mmio_region_write32(gpio->
base_addr, GPIO_CTRL_EN_INPUT_FILTER_REG_OFFSET, 0);
122 mmio_region_write32(gpio->
base_addr, GPIO_INTR_STATE_REG_OFFSET, 0xFFFFFFFFu);
136 gpio->
base_addr, GPIO_INTR_CTRL_EN_RISING_REG_OFFSET, mask, 0);
138 gpio->
base_addr, GPIO_INTR_CTRL_EN_FALLING_REG_OFFSET, mask, 0);
140 gpio->
base_addr, GPIO_INTR_CTRL_EN_LVLHIGH_REG_OFFSET, mask, 0);
142 gpio->
base_addr, GPIO_INTR_CTRL_EN_LVLLOW_REG_OFFSET, mask, 0);
147 gpio->
base_addr, GPIO_INTR_CTRL_EN_RISING_REG_OFFSET, mask, 0);
151 gpio->
base_addr, GPIO_INTR_CTRL_EN_FALLING_REG_OFFSET, mask, 0);
155 gpio->
base_addr, GPIO_INTR_CTRL_EN_LVLLOW_REG_OFFSET, mask, 0);
159 gpio->
base_addr, GPIO_INTR_CTRL_EN_LVLHIGH_REG_OFFSET, mask, 0);
163 gpio->
base_addr, GPIO_INTR_CTRL_EN_RISING_REG_OFFSET, mask, 0);
165 gpio->
base_addr, GPIO_INTR_CTRL_EN_FALLING_REG_OFFSET, mask, 0);
169 gpio->
base_addr, GPIO_INTR_CTRL_EN_RISING_REG_OFFSET, mask, 0);
171 gpio->
base_addr, GPIO_INTR_CTRL_EN_LVLLOW_REG_OFFSET, mask, 0);
175 gpio->
base_addr, GPIO_INTR_CTRL_EN_FALLING_REG_OFFSET, mask, 0);
177 gpio->
base_addr, GPIO_INTR_CTRL_EN_LVLHIGH_REG_OFFSET, mask, 0);
188 if (gpio == NULL || state == NULL) {
192 *state = mmio_region_read32(gpio->
base_addr, GPIO_DATA_IN_REG_OFFSET);
214 mmio_region_write32(gpio->
base_addr, GPIO_DIRECT_OUT_REG_OFFSET, state);
221 return gpio_masked_bit_write(gpio, GPIO_MASKED_OUT_LOWER_REG_OFFSET,
222 GPIO_MASKED_OUT_UPPER_REG_OFFSET, pin, state);
227 return gpio_masked_write(gpio, GPIO_MASKED_OUT_LOWER_REG_OFFSET,
228 GPIO_MASKED_OUT_UPPER_REG_OFFSET, mask, state);
237 mmio_region_write32(gpio->
base_addr, GPIO_DIRECT_OE_REG_OFFSET, state);
245 return gpio_masked_bit_write(gpio, GPIO_MASKED_OE_LOWER_REG_OFFSET,
246 GPIO_MASKED_OE_UPPER_REG_OFFSET, pin, state);
252 return gpio_masked_write(gpio, GPIO_MASKED_OE_LOWER_REG_OFFSET,
253 GPIO_MASKED_OE_UPPER_REG_OFFSET, mask, state);
266 gpio->
base_addr, GPIO_CTRL_EN_INPUT_FILTER_REG_OFFSET, mask, 0);
270 gpio->
base_addr, GPIO_CTRL_EN_INPUT_FILTER_REG_OFFSET, mask, 0);