/** * \brief Disable SPI and change to GPIO */ void epd_spi_detach (void) { spi_disable(EPD_SPI_ID); ioport_enable_pin(EPD_SPI_CLK_PIN); ioport_enable_pin(EPD_SPI_MOSI_PIN); ioport_enable_pin(EPD_SPI_MISO_PIN); config_gpio_dir_o(EPD_SPI_CLK_PIN); config_gpio_dir_o(EPD_SPI_MOSI_PIN); config_gpio_dir_o(EPD_SPI_MISO_PIN); set_gpio_low(EPD_SPI_CLK_PIN); set_gpio_low(EPD_SPI_MOSI_PIN); set_gpio_low(EPD_SPI_MISO_PIN); }
int I2C_init( void ) { twi_options_t opt; twi_slave_fct_t twi_slave_fct; int status; double total = 0; // Initialize and enable interrupt irq_initialize_vectors(); cpu_irq_enable(); // TWI gpio pins configuration gpio_enable_module(TWI_GPIO_MAP, sizeof(TWI_GPIO_MAP) / sizeof(TWI_GPIO_MAP[0])); // initialize the interrupt flag for alerting the Pi of new data (TWI = Three Wire Interface for us) ioport_enable_pin(I2C_FLAG); ioport_set_pin_dir(I2C_FLAG,IOPORT_DIR_OUTPUT); ioport_set_pin_level(I2C_FLAG,false); // options settings opt.pba_hz = FOSC0; opt.speed = TWI_SPEED; opt.chip = EEPROM_ADDRESS; // initialize TWI driver with options twi_slave_fct.rx = &twi_slave_rx; twi_slave_fct.tx = &twi_slave_tx; twi_slave_fct.stop = &twi_slave_stop; status = twi_slave_init(&AVR32_TWI, &opt, &twi_slave_fct ); return (&s_memory[0] ); }
void init_gpio_pins(void) { ioport_enable_pin(LED_1); ioport_enable_pin(LED_2); ioport_enable_pin(LED_3); ioport_enable_pin(HM_10_RESET); ioport_enable_pin(HM_10_DD); ioport_enable_pin(HM_10_DC); ioport_enable_pin(HM_10_MSG); ioport_set_pin_dir(LED_1, IOPORT_DIR_OUTPUT); ioport_set_pin_dir(LED_2, IOPORT_DIR_OUTPUT); ioport_set_pin_dir(LED_3, IOPORT_DIR_OUTPUT); ioport_set_pin_dir(HM_10_RESET, IOPORT_DIR_INPUT); ioport_set_pin_dir(HM_10_DD, IOPORT_DIR_INPUT); ioport_set_pin_dir(HM_10_DC, IOPORT_DIR_INPUT); ioport_set_pin_dir(HM_10_MSG, IOPORT_DIR_INPUT); ioport_set_pin_level(LED_1, false); ioport_set_pin_level(LED_2, false); ioport_set_pin_level(LED_3, false); // LED's on /*ioport_set_pin_level(HM_10_DD, false); // DC,DD low ioport_set_pin_level(HM_10_DC, false); ioport_set_pin_level(HM_10_RESET, false); // HM-10 in reset (reset low)*/ }
static void _dbg_usart_pins_init(void) { #ifdef DBG_USART_PIN_EN ioport_set_pin_dir(DBG_USART_PIN_EN, IOPORT_DIR_OUTPUT); ioport_enable_pin(DBG_USART_PIN_EN); ioport_set_pin_level(DBG_USART_PIN_EN, DBG_USART_PIN_EN_LEVEL); #endif #if defined(DBG_USART_PIN_TX) ioport_set_pin_mode(DBG_USART_PIN_TX, DBG_USART_PIN_TX_MUX); ioport_disable_pin(DBG_USART_PIN_TX); #endif #if defined(DBG_USART_PIN_RX) ioport_set_pin_mode(DBG_USART_PIN_RX, DBG_USART_PIN_TX_MUX); ioport_disable_pin(DBG_USART_PIN_RX); #endif }
/** * \brief Reset AT24CXX. * * Send 9 clock cycles to reset memory state. * * \note IO mode is used in this function, so it can be used even if TWI is not * enabled. */ void at24cxx_reset(void) { uint32_t i; /* MEM reset * a) Clock up to 9 cycles (use 100K) * b) look for SDA high in each cycle while SCL is high and then * c) Create a start condition as SDA is high */ /* - Enable pin output mode */ ioport_set_pin_dir(BOARD_CLK_TWI_EEPROM, IOPORT_DIR_OUTPUT); ioport_set_pin_level(BOARD_CLK_TWI_EEPROM, 1); ioport_enable_pin(BOARD_CLK_TWI_EEPROM); for (i = 0; i < 10; i ++) { delay_us(5); ioport_set_pin_level(BOARD_CLK_TWI_EEPROM, 0); delay_us(5); ioport_set_pin_level(BOARD_CLK_TWI_EEPROM, 1); } /* - Restore pin peripheral mode */ ioport_set_pin_mode(BOARD_CLK_TWI_EEPROM, BOARD_CLK_TWI_MUX_EEPROM); ioport_disable_pin(BOARD_CLK_TWI_EEPROM); /* - Start condition will do on R/W start */ }
OSStatus platform_gpio_init( const platform_gpio_t* gpio, platform_pin_config_t config ) { ioport_mode_t mode; enum ioport_direction direction; OSStatus err = kNoErr; platform_mcu_powersave_disable(); require_action_quiet( gpio != NULL, exit, err = kParamErr); switch ( config ) { case INPUT_PULL_UP: { direction = IOPORT_DIR_INPUT; mode = IOPORT_MODE_PULLUP; break; } case INPUT_PULL_DOWN: { direction = IOPORT_DIR_INPUT; mode = IOPORT_MODE_PULLDOWN; break; } case INPUT_HIGH_IMPEDANCE: { direction = IOPORT_DIR_INPUT; mode = 0; break; } case OUTPUT_PUSH_PULL: { direction = IOPORT_DIR_OUTPUT; mode = 0; break; } case OUTPUT_OPEN_DRAIN_NO_PULL: { direction = IOPORT_DIR_OUTPUT; mode = IOPORT_MODE_OPEN_DRAIN; break; } case OUTPUT_OPEN_DRAIN_PULL_UP: { direction = IOPORT_DIR_OUTPUT; mode = IOPORT_MODE_OPEN_DRAIN | IOPORT_MODE_PULLUP; break; } default: { err = kParamErr; goto exit; } } ioport_enable_pin ( gpio->pin ); ioport_set_pin_mode( gpio->pin, mode ); ioport_set_pin_dir ( gpio->pin, direction ); exit: platform_mcu_powersave_enable(); return err; }
void Gpio::init(ioport_direction dir) { ioport_enable_pin(_pin); ioport_set_pin_dir(_pin, dir); }