void SPIClass::begin() { int ret =0; int max_speed = 0, default_mode=0; int mode; hw_pinMode(SPI_CS, IO_SPI_FUNC); //CS hw_pinMode(SPI_MOSI, IO_SPI_FUNC); //MOSI hw_pinMode(SPI_MISO, IO_SPI_FUNC); //MISO hw_pinMode(SPI_CLK, IO_SPI_FUNC); //CLK if (!_fd) _fd = open(spi_name, O_RDWR); if (_fd < 0) pabort("can't open device"); _speed = 500000; ret = ioctl(_fd, SPI_IOC_RD_MODE, &default_mode); if (ret == -1) pabort("can't get spi mode"); mode = default_mode; ret = ioctl(_fd, SPI_IOC_RD_MAX_SPEED_HZ, &max_speed); if (ret == -1) pabort("can't get max speed hz"); _speed = max_speed; printf("spi mode: 0x%x\n", mode); printf("bits per word: %d\n", _bits_per_word); printf("max speed: %d Hz (%d KHz)\n", _speed, _speed/1000); }
void pinMode(uint8_t pin, uint8_t mode) { switch (mode) { case INPUT: case OUTPUT: hw_pinMode(pin, mode); break; case INPUT_PULLUP: hw_pinMode(pin, 8); break; default: break; } }
void TwoWire::begin(void) { rxBufferIndex = 0; rxBufferLength = 0; txBufferIndex = 0; txBufferLength = 0; hw_pinMode(I2C0_SDA, IO_I2C_FUNC); //SDA0 hw_pinMode(I2C0_SCL, IO_I2C_FUNC); //SCL0 if (!i2c_handle) { if ((i2c_handle = open("/dev/i2c-0", O_RDWR)) < 0) pabort("can't open device /dev/i2c-0"); } }