uint8_t gpio_input_bit(uint8_t port, uint8_t pin) { if (*GPIO_IDR(port) & (1 << pin)) return 1; return 0; }
static int but_value(void) { int v; v = reg_rd(GPIO_IDR(GPIOA)); v &= 0x0A; v ^= 0x0A; return v; }
// Read input data bit from pGrpDev->ucPin uint8_t bb_read_wire_data_bit(sGrpDev* pGrpDev) { volatile uint8_t result = 0; result = GPIO_IDR(pGrpDev->pPort) & (1 << pGrpDev->ucPin); if (result != 0) { result = 1; } else { result = 0; } return result; }
static inline void main_event(void) { // Delay(2000); static uint8_t foo = 0; foo++; #if 0 if (!(foo % 2)) { gpio_set(B_TX_PORT, B_TX_PIN); } else { gpio_clear(B_TX_PORT, B_TX_PIN); } #endif #if 0 if (!(foo % 2)) { gpio_clear(A_TX_PORT, A_TX_PIN); } else { gpio_set(A_TX_PORT, A_TX_PIN); } #endif #if 1 /* passthrough B_RX to A_TX */ if (GPIO_IDR(B_RX_PORT) & B_RX_PIN) { gpio_set(A_TX_PORT, A_TX_PIN); } else { gpio_clear(A_TX_PORT, A_TX_PIN); } #endif /* passthrough A_RX to B_TX */ if (gpio_get(A_RX_PORT, A_RX_PIN)) { gpio_set(B_TX_PORT, B_TX_PIN); LED_ON(2); } else { gpio_clear(B_TX_PORT, B_TX_PIN); LED_OFF(2); } }
/** * Timer 2 interrupt service routine */ void tim2_isr(void) { TIM_SR(SSI_TIMER) &= ~TIM_SR_UIF;// Clear Interrupt Flag // Check state and run correct handler action switch(ssi_state) { case(SSI_START): // SSI Start of Frame { gpio_clear(SSI_GPIO, SSI_CLK_PIN);// Set the clock low ssi_state = SSI_CLK_LOW; // Change SSI state break; } case(SSI_CLK_HIGH): // SSI Clock High-to-Low { gpio_clear(SSI_GPIO, SSI_CLK_PIN);// Set clock low u8 input_bit = GPIO_IDR(SSI_GPIO) & SSI_DATA_PIN;// Read bit on pin 10 ssi_bit_handler(input_bit); // Call bit handler ssi_state = SSI_CLK_LOW; break; } case(SSI_CLK_LOW): // SSI Clock Low-to-High { // Set clock high gpio_set(SSI_GPIO, SSI_CLK_PIN); if(ssi_counter == 0) { ssi_state = SSI_IDLE; ssi_data_ready_flag = true; TIM_CR1(SSI_TIMER) &= ~TIM_CR1_CEN; // Turn off timer } else ssi_state = SSI_CLK_HIGH; break; } case(SSI_IDLE): // SSI Idle (Not Used) break; default: break; } }
int bumpersensor_obstacle_detected(device *dev) { device_data_bumpersensor *dd = (device_data_bumpersensor *)dev->data; return ((GPIO_IDR(dd->port) & dd->pin) == 0); }
/* On rare occassions, the I2C device will get confused, either because we missed * a timing requirement, or it is just stupid. Regardless, it holds SDA low waiting * for some unknown action from the master. This keeps the bus BUSY and prevents * any further communication. This condition is fixed by manually clocking SCL * until SDA is released by the slave. As far as it is concerned, we just completed * a normal transaction. */ static int i2c_force_clear_busy(struct i2c_dev *i2c) { if (!i2c) { return -1; } int count = 10000; switch (i2c->port) { case 1: /* Set pins to output/input */ gpio_moder(GPIOB, I2C1_SCL, GPIO_MODER_OUT); gpio_moder(GPIOB, I2C1_SDA, GPIO_MODER_IN); /* Toggle clock until bus no longer busy */ while (!(*GPIO_IDR(GPIOB) & GPIO_IDR_PIN(I2C1_SDA))) { if (!count--) { /* Out of time, perhaps the last ditch effort will save us. */ break; } /* Toggle clock */ *GPIO_ODR(GPIOB) ^= GPIO_ODR_PIN(I2C1_SCL); for (volatile int delay = 100; delay > 0; delay--); } gpio_moder(GPIOB, I2C1_SCL, GPIO_MODER_ALT); gpio_moder(GPIOB, I2C1_SDA, GPIO_MODER_ALT); for (volatile int delay = 100; delay > 0; delay--); break; case 2: /* Set pins to output/input */ gpio_moder(GPIOB, I2C2_SCL, GPIO_MODER_OUT); gpio_moder(GPIOB, I2C2_SDA, GPIO_MODER_IN); /* Toggle clock until SDA raised */ while (!(*GPIO_IDR(GPIOB) & GPIO_IDR_PIN(I2C2_SDA))) { if (!count--) { /* Out of time, perhaps the last ditch effort will save us. */ break; } /* Toggle clock */ *GPIO_ODR(GPIOB) ^= GPIO_ODR_PIN(I2C2_SCL); for (volatile int delay = 100; delay > 0; delay--); } gpio_moder(GPIOB, I2C2_SCL, GPIO_MODER_ALT); gpio_moder(GPIOB, I2C2_SDA, GPIO_MODER_ALT); for (volatile int delay = 100; delay > 0; delay--); break; default: return -1; } /* Make sure the peripheral recognizes that the bus is now free */ if (*I2C_SR2(i2c->port) & I2C_SR2_BUSY) { /* Last ditch effort */ if (i2c_reset(i2c) || (*I2C_SR2(i2c->port) & I2C_SR2_BUSY)) { /* Failed to reset */ printk("I2C: BUSY flag failed to clear.\r\nI2C: I have tried everything I know :(. At this point, reset is your best option.\r\n"); return -1; } } return 0; }
/** @brief Read from a Port Read the current value of the given GPIO port. Only the lower 16 bits contain valid pin data. @param[in] gpioport Unsigned int32. Port identifier @ref gpio_port_id @return Unsigned int16. The value held in the specified GPIO port. */ u16 gpio_port_read(u32 gpioport) { return (u16)GPIO_IDR(gpioport); }
int button_is_pressed(device *dev) { device_data_button *dd = (device_data_button *)dev->data; return !((GPIO_IDR(dd->port) & dd->pin) == 0); }
unsigned char vga_is_frameready ( void ) { return ( GPIO_IDR ( GPIOB ) & (1<<13) ); }
void gpio_toggle(u32 gpioport, u16 gpios) { GPIO_ODR(gpioport) = GPIO_IDR(gpioport) ^ gpios; }
uint16_t gpio_port_read(uint32_t gpioport) { return (uint16_t)GPIO_IDR(gpioport); }