void SMI::opWrite() { //data=01 digitalWrite (_dataPin, LOW); clockPulse(); digitalWrite (_dataPin, HIGH); clockPulse(); }
static uint8_t shiftIn(uint8_t dataPin, uint8_t clockPin) { int8_t i; uint8_t temp; uint8_t data = 0; clockPulse(clockPin); for (i = 7; i >= 0; i--) { temp = PINC; _delay_us(0.2d); temp &= (1 << dataPin); temp >>= dataPin; data |= (temp << i); // HACK: Contrary to all tutorials and the 4021 chip's data-, // I seem to have to use two clock pulses instead of one. // Clearly I have misunderstood something here but this code // works so I'm going with it! clockPulse(clockPin); clockPulse(clockPin); } return data; }
void SMI::opRead() { //data=10 digitalWrite (_dataPin, HIGH); clockPulse(); digitalWrite (_dataPin, LOW); clockPulse(); }
// Private method. Writes pixel data without brightness scaling. static void raw_write(DotStarObject *self, uint8_t *ptr, uint32_t len) { if(self->fd >= 0) { // Hardware SPI xfer[1].tx_buf = (unsigned long)ptr; xfer[1].len = len; // All that spi_ioc_transfer struct stuff earlier in // the code is so we can use this single ioctl to concat // the header/data/footer into one operation: (void)ioctl(self->fd, SPI_IOC_MESSAGE(3), xfer); } else if(self->dataMask) { // Bitbang unsigned char byte, bit; *gpioClr = self->dataMask; for(bit=0; bit<32; bit++) { // Header clockPulse(self->clockMask); } while(len--) { byte = *ptr++; for(bit = 0x80; bit; bit >>= 1) { if(byte & bit) *gpioSet = self->dataMask; else *gpioClr = self->dataMask; clockPulse(self->clockMask); } } *gpioClr = self->dataMask; for(bit=0; bit<32; bit++) { // Footer clockPulse(self->clockMask); } }
// Preamble + SFD void SMI::start() { //Preamble digitalWrite (_dataPin, HIGH); for (int smi_i=0; smi_i<32; smi_i++) { clockPulse(); } //SFD digitalWrite (_dataPin, LOW); clockPulse(); digitalWrite (_dataPin, HIGH); clockPulse(); }
// Send register address void SMI::putAddress(byte HB, byte LB) { int smi_i; for (smi_i=1; smi_i>=0; smi_i--){ if ((HB &(1<<smi_i))==0) { digitalWrite (_dataPin, LOW); } else { digitalWrite (_dataPin, HIGH); } clockPulse(); } for (smi_i=7; smi_i>=0; smi_i--){ if ((LB &(1<<smi_i))==0) { digitalWrite (_dataPin, LOW); } else { digitalWrite (_dataPin, HIGH); } clockPulse(); } }
void SMI::sendData(byte target[], int arraySize) { int smi_i, smi_j; for (smi_j=0; smi_j<arraySize; smi_j++) { for (smi_i=7; smi_i>=0; smi_i--) { if ((target[smi_j] & (1<<smi_i))==0) { digitalWrite (_dataPin, LOW); } else { digitalWrite (_dataPin, HIGH); } clockPulse(); } } }
int QEncoder::getSample() { quint16 sample=0; interrupts(0); m_gpio.bitSet (m_bitClock); for (int n=0;n<13;n++) { clockPulse(); int bit = m_gpio.bitValue(m_bitData); //qDebug() << bit; sample |= bit; sample <<=1; } interrupts(1); return sample; }
void SMI::readTurnA() { pinMode(_dataPin, INPUT); clockPulse(); }
void SMI::writeTurnA() { digitalWrite (_dataPin, HIGH); clockPulse(); digitalWrite (_dataPin, LOW); clockPulse(); }