/*! * \brief Set the specified chip select to a given level. */ static int Stm32SpiChipSelect(uint_fast8_t cs, uint_fast8_t hi) { /* Fixme: Check for cs != 0 */ GpioPinConfigSet(SPIBUS_CS_PORT, SPIBUS_CS_PIN, GPIO_CFG_OUTPUT); GpioPinSet(SPIBUS_CS_PORT, SPIBUS_CS_PIN, hi); return 0; }
/*! * \brief Set the specified chip select to a given level. */ static GSPIREG *GpioSpi0ChipSelect(uint_fast8_t cs, uint_fast8_t hi) { GSPIREG *rc; switch (cs) { case 0: /* If CS0 is undefined, we assume permanent selection. */ #if defined(SBBI0_CS0_BIT) GpioPinSet(SBBI0_CS0_PORT, SBBI0_CS0_BIT, hi); GpioPinConfigSet(SBBI0_CS0_PORT, SBBI0_CS0_BIT, GPIO_CFG_OUTPUT); #endif rc = &gspi_reg0; break; #if defined(SBBI0_CS1_BIT) case 1: GpioPinSet(SBBI0_CS1_PORT, SBBI0_CS1_BIT, hi); GpioPinConfigSet(SBBI0_CS1_PORT, SBBI0_CS1_BIT, GPIO_CFG_OUTPUT); rc = &gspi_reg1; break; #endif #if defined(SBBI0_CS2_BIT) case 2: GpioPinSet(SBBI0_CS2_PORT, SBBI0_CS2_BIT, hi); GpioPinConfigSet(SBBI0_CS2_PORT, SBBI0_CS2_BIT, GPIO_CFG_OUTPUT); rc = &gspi_reg2; break; #endif #if defined(SBBI0_CS3_BIT) case 3: GpioPinSet(SBBI0_CS3_PORT, SBBI0_CS3_BIT, hi); GpioPinConfigSet(SBBI0_CS3_PORT, SBBI0_CS3_BIT, GPIO_CFG_OUTPUT); rc = &gspi_reg3; break; #endif default: errno = EIO; rc = NULL; break; } return rc; }
/* Idle clock is high and data is captured on the rising edge. */ static void SpiMode3Transfer(GSPIREG *gspi, CONST uint8_t *txbuf, uint8_t *rxbuf, int xlen) { #if defined(SBBI0_SCK_BIT) uint_fast8_t mask; while (xlen--) { for (mask = 0x80; mask; mask >>= 1) { NutMicroDelay(gspi->gspi_dly_rate); GpioPinSetLow(SBBI0_SCK_PORT, SBBI0_SCK_BIT); #if defined(SBBI0_MOSI_BIT) if (txbuf) { GpioPinSet(SBBI0_MOSI_PORT, SBBI0_MOSI_BIT, (*txbuf & mask) != 0); } #endif /* SBBI0_MOSI_BIT */ NutMicroDelay(gspi->gspi_dly_rate); GpioPinSetHigh(SBBI0_SCK_PORT, SBBI0_SCK_BIT); #if defined(SBBI0_MISO_BIT) if (rxbuf) { if (GpioPinGet(SBBI0_MISO_PORT, SBBI0_MISO_BIT)) { *rxbuf |= mask; } else { *rxbuf &= ~mask; } } #endif /* SBBI0_MISO_BIT */ } if (txbuf) { txbuf++; } if (rxbuf) { rxbuf++; } } #endif /* SBBI0_SCK_BIT */ }
void BspDebugLedSet(uint8_t ledmsk) { GpioPinSet(DEBUG_LED_PORT,DEBUG_LED1,(ledmsk&(1<<0))?0:1); GpioPinSet(DEBUG_LED_PORT,DEBUG_LED2,(ledmsk&(1<<1))?0:1); }