void Adafruit_PCD8544::data(uint8_t c) { pinSetFast(_dc); //DC HIGH //digitalWrite(_dc, HIGH); if (_cs > 0) pinResetFast(_cs); //CS LOW //digitalWrite(_cs, LOW); fastSPIwrite(c); if (_cs > 0) pinSetFast(_cs); //CS HIGH //digitalWrite(_cs, HIGH); }
void NexaCtrl::TransmitLatch2(void) { // high for a moment 275 pinSetFast(tx_pin_); delayMicroseconds(kPulseLow0); // low for 2675 for latch 2 pinResetFast(tx_pin_); delayMicroseconds(2675); }
void NexaCtrl::TransmitLatch1(void) { // bit of radio shouting before we start pinSetFast(tx_pin_); delayMicroseconds(kPulseLow0); // low for 9900 for latch 1 pinResetFast(tx_pin_); delayMicroseconds(9900); }
//Hardware SPI inline void Adafruit_PCD8544::fastSPIwrite(uint8_t d) { if (hwSPI) { SPI.transfer(d); return; } for (uint8_t bit = 0; bit < 8; bit++) { pinResetFast(_sclk); // Clock Low if (d & (1 << (7-bit))) // walks down mask from bit 7 to bit 0 pinSetFast(_din); // Data High else pinResetFast(_din); // Data Low pinSetFast(_sclk); // Clock High } }
void NexaCtrl::Transmit(int pulse_length) { int pulse_count; int transmit_count; // Sending the data requires very precise timing, which can be destroyed by interrupts noInterrupts(); for (transmit_count = 0; transmit_count < 2; transmit_count++) { if (led_pin_ > 0) { pinSetFast(led_pin_); } TransmitLatch1(); TransmitLatch2(); /* * Transmit the actual message * every wire bit starts with the same short high pulse, followed * by a short or long low pulse from an array of low pulse lengths */ for (pulse_count = 0; pulse_count < pulse_length; pulse_count++) { pinSetFast(tx_pin_); delayMicroseconds(kPulseHigh); pinResetFast(tx_pin_); delayMicroseconds(low_pulse_array[pulse_count]); } TransmitLatch2(); if (led_pin_ > 0) { digitalWrite(led_pin_, LOW); } delayMicroseconds(10000); } // Enable interrupts again interrupts(); }
uint8_t RFID::softSPITranser(uint8_t data) { uint8_t b=0; for (uint8_t bit = 0; bit < 8; bit++) { if (data & (1 << (7-bit))) // walks down mask from bit 7 to bit 0 pinSetFast(_mosiPin); // Data High else pinResetFast(_mosiPin); // Data Low pinSetFast(_clockPin); // Clock High b <<= 1; if (pinReadFast(_misoPin)) b |= 1; pinResetFast(_clockPin); // Clock Low } return b; }
void Adafruit_PCD8544::display(void) { uint8_t col, maxcol, p; for(p = 0; p < 6; p++) { #ifdef enablePartialUpdate // check if this page is part of update if ( yUpdateMin >= ((p+1)*8) ) { continue; // nope, skip it! } if (yUpdateMax < p*8) { break; } #endif command(PCD8544_SETYADDR | p); #ifdef enablePartialUpdate col = xUpdateMin; maxcol = xUpdateMax; #else // start at the beginning of the row col = 0; maxcol = LCDWIDTH-1; #endif command(PCD8544_SETXADDR | col); digitalWrite(_dc, HIGH); if (_cs > 0) pinResetFast(_cs); //CS LOW //digitalWrite(_cs, LOW); for(; col <= maxcol; col++) { //uart_putw_dec(col); //uart_putchar(' '); fastSPIwrite(pcd8544_buffer[(LCDWIDTH*p)+col]); } if (_cs > 0) pinSetFast(_cs); //CS HIGH //digitalWrite(_cs, HIGH); } command(PCD8544_SETYADDR ); // no idea why this is necessary but it is to finish the last byte? #ifdef enablePartialUpdate xUpdateMin = LCDWIDTH - 1; xUpdateMax = 0; yUpdateMin = LCDHEIGHT-1; yUpdateMax = 0; #endif }
uint8_t Sd2Card::sparkSPISend(uint8_t data) { uint8_t b=0; if (SPImode_) { // SPI Mode is Hardware so use Spark SPI function b = SPI.transfer(data); } else { // SPI Mode is Software so use bit bang method for (uint8_t bit = 0; bit < 8; bit++) { if (data & (1 << (7-bit))) // walks down mask from bit 7 to bit 0 pinSetFast(mosiPin_); // Data High else pinResetFast(mosiPin_); // Data Low pinSetFast(clockPin_); // Clock High b <<= 1; if (pinReadFast(misoPin_)) b |= 1; pinResetFast(clockPin_); // Clock Low } } return b; }
// Here is the meat and gravy void SoftPWM_Timer_Interrupt(void) { uint8_t i; int16_t newvalue; int16_t direction; if(++_isr_softcount == 0) { // set all channels high - let's start again // and accept new checkvals for (i = 0; i < SOFTPWM_MAXCHANNELS; i++) { if (_softpwm_channels[i].fadeuprate > 0 || _softpwm_channels[i].fadedownrate > 0) { // we want to fade to the new value direction = _softpwm_channels[i].pwmvalue - _softpwm_channels[i].checkval; // we will default to jumping to the new value newvalue = _softpwm_channels[i].pwmvalue; if (direction > 0 && _softpwm_channels[i].fadeuprate > 0) { newvalue = _softpwm_channels[i].checkval + _softpwm_channels[i].fadeuprate; if (newvalue > _softpwm_channels[i].pwmvalue) newvalue = _softpwm_channels[i].pwmvalue; } else if (direction < 0 && _softpwm_channels[i].fadedownrate > 0) { newvalue = _softpwm_channels[i].checkval - _softpwm_channels[i].fadedownrate; if (newvalue < _softpwm_channels[i].pwmvalue) newvalue = _softpwm_channels[i].pwmvalue; } _softpwm_channels[i].checkval = newvalue; } else // just set the channel to the new value _softpwm_channels[i].checkval = _softpwm_channels[i].pwmvalue; // now set the pin high (if not 0) if (_softpwm_channels[i].checkval > 0) // don't set if checkval == 0 { if (_softpwm_channels[i].polarity == SOFTPWM_NORMAL) //PIN_MAP[_softpwm_channels[i].pin].gpio_peripheral->BSRR = PIN_MAP[_softpwm_channels[i].pin].gpio_pin; //hi pinSetFast(_softpwm_channels[i].pin); else //PIN_MAP[_softpwm_channels[i].pin].gpio_peripheral->BRR = PIN_MAP[_softpwm_channels[i].pin].gpio_pin; //lo pinResetFast(_softpwm_channels[i].pin); } } } for (i = 0; i < SOFTPWM_MAXCHANNELS; i++) { if (_softpwm_channels[i].pin >= 0) // if it's a valid pin { if (_softpwm_channels[i].checkval == _isr_softcount) // if we have hit the width { // turn off the channel if (_softpwm_channels[i].polarity == SOFTPWM_NORMAL) //PIN_MAP[_softpwm_channels[i].pin].gpio_peripheral->BRR = PIN_MAP[_softpwm_channels[i].pin].gpio_pin; //lo pinResetFast(_softpwm_channels[i].pin); else //PIN_MAP[_softpwm_channels[i].pin].gpio_peripheral->BSRR = PIN_MAP[_softpwm_channels[i].pin].gpio_pin; //hi pinSetFast(_softpwm_channels[i].pin); } } } }