void lcdInit( void ) { pinConfig( LCD_SDA, OUT ); pinConfig( LCD_SCL, OUT ); pinConfig( LCD_RS, OUT ); pinConfig( LCD_CS, OUT ); pinConfig( LCD_PSB, OUT ); pinConfig( LCD_PSI2B, OUT ); pinConfig( LCD_BL, OUT ); pinSet( LCD_BL, HIGH ); pinSet( LCD_RS, HIGH ); pinSet( LCD_CS, HIGH ); // SPI pinSet( LCD_PSB, LOW ); pinSet( LCD_PSI2B, HIGH ); lcdWriteCommand( 0x38 ); //FUNCTION SET 8 bit,N=1 2-line display mode,5*7dot delay( 100 ); lcdWriteCommand( 0x39 ); //FUNCTION SET 8 bit,N=1 2-line display mode,5*7dot IS=1 delay( 100 ); lcdWriteCommand( 0x1c ); //Internal OSC frequency adjustment 183HZ bias will be 1/4 delay( 100 ); lcdWriteCommand( 0x73 ); //Contrast control low byte delay( 100 ); lcdWriteCommand( 0x57 ); //booster circuit is turn on. /ICON display off. /Contrast control high byte delay( 100 ); lcdWriteCommand( 0x6c ); //Follower control delay( 1000 ); lcdWriteCommand( 0x0c ); //DISPLAY ON delay( 100 ); lcdWriteCommand( 0x01 ); //CLEAR DISPLAY delay( 10000 ); lcdWriteCommand( 0x06 ); //ENTRY MODE SET CURSOR MOVES TO RIGHT delay( 100 ); }
void amb8420Init(void) { RPRINTF("amb8420Init...\n"); amb8420InitSerial(); pinAsOutput(AMB8420_RESET_PORT, AMB8420_RESET_PIN); pinAsOutput(AMB8420_CONFIG_PORT, AMB8420_CONFIG_PIN); pinAsOutput(AMB8420_SLEEP_PORT, AMB8420_SLEEP_PIN); pinAsOutput(AMB8420_TRX_DISABLE_PORT, AMB8420_TRX_DISABLE_PIN); // pinAsOutput(AMB8420_DATA_REQUEST_PORT, AMB8420_DATA_REQUEST_PIN); pinAsInput(AMB8420_RTS_PORT, AMB8420_RTS_PIN); // pinAsInput(AMB8420_DATA_INDICATE_PORT, AMB8420_DATA_INDICATE_PIN); pinSet(AMB8420_CONFIG_PORT, AMB8420_CONFIG_PIN); // pinClear(AMB8420_DATA_REQUEST_PORT, AMB8420_DATA_REQUEST_PIN); // in case interrupts are used (for non-command mode): //pinIntRising(AMB8420_DATA_INDICATE_PORT, AMB8420_DATA_INDICATE_PIN); //pinEnableInt(AMB8420_DATA_INDICATE_PORT, AMB8420_DATA_INDICATE_PIN); initResult = amb8420Reset(); // make sure low power mode is enabled pinSet(AMB8420_TRX_DISABLE_PORT, AMB8420_TRX_DISABLE_PIN); pinSet(AMB8420_SLEEP_PORT, AMB8420_SLEEP_PIN); alarmInit(&radioResetTimer, onRadioReset, NULL); alarmSchedule(&radioResetTimer, RADIO_RESET_INTERVAL); RPRINTF("..done\n"); }
void modemInit( void ) { //pinConfig( PA2, ALT ); //pinConfig( PA3, IN ); //USART2->BRR = 24000000/ 115200; //( ( (ulClock >> 3 ) / BOOT_BAUDRATE ) << 4 ) + ( ( ( ulClock / BOOT_BAUDRATE ) ) & 0x0007 ); //USART2->CR3 = 0;//|= USART_ONEBITE; //USART2->CR1 = ( USART_UE | USART_RXNEIE | USART_TE | USART_RE ); comConfig( COM2, 0, RTS|CTS, 19200 ); streamEnableActionChars( COM2 ); streamSetActionChars( COM2, (u8*)AT_ACTIONCHARS ); streamSetGet( MODEM_COM, cmdGetsModem ); streamSetRXBuffer( MODEM_COM, globalCOM2RXBuffer, __PYGMYCOM2BUFFERLEN ); streamSetPut( MODEM_COM, putsUSART2 ); pinConfig( D1, OUT ); pinConfig( D0, OUT ); pinSet( D1, LOW ); pinSet( D0, LOW ); pinConfig( D3, IN ); pinConfig( T1, OUT ); //pinSet( D0, HIGH ); //delay( 15000 ); //pinSet( D0, LOW ); pinInterrupt( blink, D3, TRIGGER_RISING|TRIGGER_FALLING, 7 ); cmdInitQueue( &globalModemQueue ); taskNew( "modemcmd", 500, 500, 0, (void*)DriverThread_ProcessCommands ); }
void blink( void ) { if( pinGet( T1 ) ){ pinSet( T1, LOW ); } else{ pinSet( T1, HIGH ); } // else }
void Adafruit_DotStar::sw_spi_out(uint8_t n) { // Bitbang SPI write for(uint8_t i=8; i--; n <<= 1) { if(n & 0x80) pinSet(dataPin, HIGH); else pinSet(dataPin, LOW); pinSet(clockPin, HIGH); pinSet(clockPin, LOW); } }
void amb8420Off(void) { if (isOn) { // RPRINTF("amb842Off\n"); isOn = false; pinSet(AMB8420_TRX_DISABLE_PORT, AMB8420_TRX_DISABLE_PIN); pinSet(AMB8420_SLEEP_PORT, AMB8420_SLEEP_PIN); } }
Amb8420InitCode_e amb8420Reset(void) { bool ok; Handle_t h; Amb8420InitCode_e result = AMB8420_INIT_HARD_FAIL; RPRINTF("amb8420Reset\n"); if (serial[AMB8420_UART_ID].function != SERIAL_FUNCTION_RADIO) { amb8420InitSerial(); } AMB8420ModeContext_t ctx; // the chip cannot be configured while in sleep mode AMB8420_ENTER_ACTIVE_MODE(ctx); RPRINTF("active mode ok\n"); pinClear(AMB8420_RESET_PORT, AMB8420_RESET_PIN); ledsSet(0xff); mdelay(200); ledsSet(0); pinSet(AMB8420_RESET_PORT, AMB8420_RESET_PIN); mdelay(500); // wait for initialization to complete AMB8420_WAIT_FOR_RTS_READY(ok); if (!ok) goto end; RPRINTF(" init completed\n"); ATOMIC_START(h); udelay(100); // Switch to command mode (generate falling front) pinClear(AMB8420_CONFIG_PORT, AMB8420_CONFIG_PIN); mdelay(1); pinSet(AMB8420_CONFIG_PORT, AMB8420_CONFIG_PIN); ATOMIC_END(h); // Wait for device to become ready AMB8420_WAIT_FOR_RTS_READY(ok); if (ok) { RPRINTF(" device ready\n"); result = AMB8420_INIT_SUCCESS; } else { RPRINTF(" device NOT ready\n"); } end: // restore sleep mode AMB8420_RESTORE_MODE(ctx); return result; }
static void setup(void) { pinDirection(lcdConfig.rw, Output); pinDirection(lcdConfig.rs, Output); pinDirection(lcdConfig.e, Output); pinSet(lcdConfig.rw, Low); pinSet(lcdConfig.rs, Low); pinSet(lcdConfig.e, Low); state = init0; outOfBounds = false; delay(&task, MS_TO_TICKS(50)); }
static void initIO(void) { HUB_GPIO_CLK_ENABLE(); GPIO_InitTypeDef gpioInit; gpioInit.Mode = GPIO_MODE_OUTPUT_PP; gpioInit.Pull = GPIO_PULLUP; gpioInit.Speed = GPIO_SPEED_HIGH; pinSet(hub_noe); gpioInit.Pin = hub_noe.pin; HAL_GPIO_Init(hub_noe.port, &gpioInit); pinSet(hub_noe); gpioInit.Pin = hub_r1.pin; HAL_GPIO_Init(hub_r1.port, &gpioInit); gpioInit.Pin = hub_b1.pin; HAL_GPIO_Init(hub_b1.port, &gpioInit); gpioInit.Pin = hub_g1.pin; HAL_GPIO_Init(hub_g1.port, &gpioInit); gpioInit.Pin = hub_r2.pin; HAL_GPIO_Init(hub_r2.port, &gpioInit); gpioInit.Pin = hub_g2.pin; HAL_GPIO_Init(hub_g2.port, &gpioInit); gpioInit.Pin = hub_b2.pin; HAL_GPIO_Init(hub_b2.port, &gpioInit); gpioInit.Pin = hub_a.pin; HAL_GPIO_Init(hub_a.port, &gpioInit); gpioInit.Pin = hub_b.pin; HAL_GPIO_Init(hub_b.port, &gpioInit); gpioInit.Pin = hub_c.pin; HAL_GPIO_Init(hub_c.port, &gpioInit); gpioInit.Pin = hub_d.pin; HAL_GPIO_Init(hub_d.port, &gpioInit); gpioInit.Pin = hub_clk.pin; HAL_GPIO_Init(hub_clk.port, &gpioInit); gpioInit.Pin = hub_lat.pin; HAL_GPIO_Init(hub_lat.port, &gpioInit); gpioInit.Pin = hub_time.pin; HAL_GPIO_Init(hub_time.port, &gpioInit); /**TIM10 GPIO Configuration PF6 ------> TIM10_CH1 => NOE */ gpioInit.Pin = GPIO_PIN_6; gpioInit.Mode = GPIO_MODE_AF_PP; gpioInit.Pull = GPIO_PULLUP; gpioInit.Speed = GPIO_SPEED_HIGH; gpioInit.Alternate = GPIO_AF3_TIM10; HAL_GPIO_Init(GPIOF, &gpioInit); }
/*----------------------------------------------------------------------------*/ int main(void) { const struct Pin led = pinInit(LED_PIN); pinOutput(led, false); struct Interface * const flash = init(Flash, 0); assert(flash); size_t flashSize, pageSize; enum Result res; pinSet(led); if ((res = ifGetParam(flash, IF_SIZE, &flashSize)) == E_OK) pinReset(led); assert(res == E_OK); pinSet(led); if ((res = ifGetParam(flash, IF_FLASH_PAGE_SIZE, &pageSize)) == E_OK) pinReset(led); assert(res == E_OK); uint8_t * const buffer = malloc(pageSize); for (size_t i = 0; i < pageSize; ++i) buffer[i] = i; /* Test sector erase */ const size_t address = findNearestSector(); assert(address < flashSize); pinSet(led); if ((res = ifSetParam(flash, IF_FLASH_ERASE_SECTOR, &address)) == E_OK) pinReset(led); assert(res == E_OK); pinSet(led); if ((res = program(flash, buffer, pageSize, address)) == E_OK) pinReset(led); assert(res == E_OK); pinSet(led); if ((res = verify(flash, buffer, pageSize, address)) == E_OK) pinReset(led); assert(res == E_OK); /* Page erase is not available on some parts */ while (1); return 0; }
void illuminateLEDIfThresholdMet(color_spectrum_t spectrum_irr, float total_irr) { if(use_RB_total && spectrum_irr.red > RED_THRESHOLD_AS_W_M2 && spectrum_irr.blue > BLUE_THRESHOLD_AS_W_M2) { pinSet(&LED_EN_PORT, LED_EN_PIN, HIGH); } else if(!use_RB_total && total_irr > TOTAL_TRESHOLD_AS_W_M2) { pinSet(&LED_EN_PORT, LED_EN_PIN, HIGH); } else { pinSet(&LED_EN_PORT,LED_EN_PIN, LOW); } }
/*----------------------------------------------------------------------------*/ int main(void) { const struct Pin led = pinInit(LED_PIN); pinOutput(led, false); struct Interface * const adc = init(AdcOneShot, &adcConfig); assert(adc); struct Timer * const timer = init(GpTimer, &timerConfig); assert(timer); timerSetOverflow(timer, 1000); bool event = false; timerSetCallback(timer, onTimerOverflow, &event); timerEnable(timer); while (1) { while (!event) barrier(); event = false; pinSet(led); uint16_t voltage; const size_t bytesRead = ifRead(adc, &voltage, sizeof(voltage)); assert(bytesRead == sizeof(voltage)); (void)bytesRead; /* Suppress warning */ pinReset(led); } return 0; }
/*----------------------------------------------------------------------------*/ static size_t interfaceRead(void *object, void *buffer, size_t length) { struct InterfaceWrapper * const interface = object; pinSet(interface->rx); return ifRead(interface->pipe, buffer, length); }
u8 modem_reset( u8 *ucBuffer ) { pinSet( MODEM_RESET, HIGH ); taskNewSimple( "modemreset", 3000, modemtask_reset ); return( TRUE ); }
u8 modemtask_reset( void ) { pinSet( MODEM_RESET, LOW ); taskDelete( "modemreset" ); return( TRUE ); }
u8 modemtask_onoff( void ) { pinSet( MODEM_ONOFF, LOW ); taskDelete( "modemonoff" ); return( TRUE ); }
u8 modem_onoff( u8 *ucBuffer ) { pinSet( MODEM_ONOFF, HIGH ); // Switches ONOFF to GND, must be kept low for min 1 sec taskNewSimple( "modemonoff", 1200, modemtask_onoff ); return( TRUE ); }
Servo servoAdd(Pin pin) { Servo servo = {0}; while(state.servos[servo.id].enabled) { servo.id++; if(servo.id >= MAX_SERVOS) { return (Servo){-1}; } } ServoData* servoData = &state.servos[servo.id]; servoData->enabled = true; pinDirection(pin, Output); pinSet(pin, Low); servoData->pin = pin; servoData->goal = 0; servoData->position = 0; servoData->speed = 255; return servo; }
/*----------------------------------------------------------------------------*/ static size_t interfaceWrite(void *object, const void *buffer, size_t length) { struct InterfaceWrapper * const interface = object; pinSet(interface->tx); return ifWrite(interface->pipe, buffer, length); }
void lcdWriteCommand( u16 uiCommand ) { pinSet( LCD_A0, LOW ); pygmyLCD.PortCS->BRR = pygmyLCD.PinCS; // Enables chip pygmyLCD.PortSCK->BRR = pygmyLCD.PinSCK; // verify SCK low spiWriteByte( &pygmyLCD, (u8)uiCommand ); pygmyLCD.PortCS->BSRR = pygmyLCD.PinCS; // Disables chip }
void servoRemove(Servo servo) { if((servo.id >= 0) && (servo.id < MAX_SERVOS)) { ServoData* servoData = &state.servos[servo.id]; servoData->enabled = false; pinSet(servoData->pin, Low); } }
void lcdWriteData( u16 uiData ) { pinSet( LCD_A0, HIGH ); pygmyLCD.PortCS->BRR = pygmyLCD.PinCS; // Enables chip pygmyLCD.PortSCK->BRR = pygmyLCD.PinSCK; // verify SCK low spiWriteByte( &pygmyLCD, (u8)uiData ); pygmyLCD.PortCS->BSRR = pygmyLCD.PinCS; // Disables chip }
void hih5030Init( u8 ucAnalogPin, u8 ucPowerPin ) { globalHumidityCR = 1; globalHumidityPin = ucAnalogPin; globalHumidityPower = ucPowerPin; pinConfig( ucAnalogPin, ANALOG ); if( ucPowerPin != NONE ){ pinConfig( ucPowerPin, OUT ); pinSet( ucPowerPin, HIGH ); } // if }
/*----------------------------------------------------------------------------*/ int main(void) { const uint32_t maxPeriod = captureUnitConfig.frequency / pwmUnitConfig.frequency + 1; const uint32_t minPeriod = captureUnitConfig.frequency / pwmUnitConfig.frequency - 1; setupClock(); const struct Pin led = pinInit(LED_PIN); pinOutput(led, false); struct GpTimerPwmUnit * const pwmUnit = init(GpTimerPwmUnit, &pwmUnitConfig); assert(pwmUnit); struct Pwm * const pwm = gpTimerPwmCreate(pwmUnit, OUTPUT_PIN); assert(pwm); pwmSetEdges(pwm, 0, pwmGetResolution(pwm) / 2); struct GpTimerCaptureUnit * const captureUnit = init(GpTimerCaptureUnit, &captureUnitConfig); assert(pwmUnit); struct Capture * const capture = gpTimerCaptureCreate(captureUnit, INPUT_PIN, PIN_RISING, PIN_PULLDOWN); assert(capture); uint32_t previousTime = 0; bool event = false; captureSetCallback(capture, onCaptureEvent, &event); captureEnable(capture); pwmEnable(pwm); while (1) { while (!event) barrier(); event = false; const uint32_t currentTime = captureGetValue(capture); const uint32_t period = currentTime - previousTime; if (period >= minPeriod && period <= maxPeriod) pinReset(led); else pinSet(led); previousTime = currentTime; } return 0; }
static void pulseServo(ServoData* servoData) { int16_t middle = (SERVO_MAX_TIME + SERVO_MIN_TIME) / 2; int16_t range = SERVO_MAX_TIME - SERVO_MIN_TIME; int16_t adjust = servoData->position * (range / 256); int16_t ticks = middle + adjust; atomic { if(addInterrupt_(end, servoData->pin.value, ticks)) { pinSet(servoData->pin, High); } } }
void lcdInit( void ) { spiConfig( &pygmyLCD, LCD_CS, LCD_SCK, NONE, LCD_MOSI ); pinConfig( LCD_RESET, OUT ); // We will use USART1_RTS as CS pinConfig( LCD_A0, OUT ); pinSet( LCD_RESET, LOW ); delay( 2000 ); // microseconds pinSet( LCD_RESET, HIGH ); delay( 2000 ); // microseconds lcdWriteCommand( LCD_FUNCSET | LCD_FUNCSET_H ); lcdWriteCommand( LCD_SETVOP | 55 ); lcdWriteCommand( LCD_TEMPCONTROL ); lcdWriteCommand( LCD_BIAS | LCD_BIAS_BS1|LCD_BIAS_BS0 ); lcdWriteCommand( LCD_FUNCSET ); lcdWriteCommand( LCD_DISPCONTROL | LCD_DISPCONTROL_D ); lcdSetBPP( PYGMY_PBM_1BPP ); lcdSetColor( 0xFF, 0xFF, 0xFF ); lcdBackColor( 0x00, 0x00, 0x00 ); lcdClear(); drawAll(); }
/*----------------------------------------------------------------------------*/ int main(void) { static const uint32_t address = 0; uint8_t buffer[384]; for (size_t i = 0; i < sizeof(buffer); ++i) buffer[i] = i; const struct Pin led = pinInit(LED_PIN); pinOutput(led, false); struct Interface * const eeprom = init(Eeprom, 0); assert(eeprom); uint32_t size; enum Result res; pinSet(led); if ((res = ifGetParam(eeprom, IF_SIZE, &size)) == E_OK) pinReset(led); assert(res == E_OK); assert(address < size); pinSet(led); if ((res = program(eeprom, buffer, sizeof(buffer), address)) == E_OK) pinReset(led); assert(res == E_OK); pinSet(led); if ((res = verify(eeprom, buffer, sizeof(buffer), address)) == E_OK) pinReset(led); assert(res == E_OK); while (1); return 0; }
/*----------------------------------------------------------------------------*/ int main(void) { setupClock(); const struct Pin led = pinInit(LED_PIN); pinOutput(led, false); struct Interface * const adc = init(AdcDma, &adcConfig); assert(adc); ifSetCallback(adc, onConversionCompleted, adc); struct Timer * const conversionTimer = init(GpTimer, &timerConfig); assert(conversionTimer); /* * The overflow frequency of the timer should be two times higher * than that of the hardware events for ADC. */ timerSetOverflow(conversionTimer, timerConfig.frequency / (ADC_RATE * 2)); unsigned int iteration = 0; size_t count; /* Enqueue buffers */ while (ifGetParam(adc, IF_AVAILABLE, &count) == E_OK && count > 0) { const size_t index = iteration++ % BUFFER_COUNT; ifRead(adc, buffers[index], sizeof(buffers[index])); } /* Start conversion */ timerEnable(conversionTimer); while (1) { while (!event) barrier(); event = false; pinSet(led); while (ifGetParam(adc, IF_AVAILABLE, &count) == E_OK && count > 0) { const size_t index = iteration++ % BUFFER_COUNT; ifRead(adc, buffers[index], sizeof(buffers[index])); } pinReset(led); } return 0; }
void lcdWriteData( u8 dat ) { u8 i; pinSet( LCD_SCL, LOW ); pinSet( LCD_CS, LOW ); pinSet( LCD_RS, HIGH ); for( i = 0; i < 8; i++ ) { if ( dat & 0x80 ) { pinSet( LCD_SDA, HIGH ); } else { pinSet( LCD_SDA, LOW ); } //else pinSet( LCD_SCL, LOW ); dat <<= 1; pinSet( LCD_SCL, HIGH ); } // for pinSet( LCD_CS, HIGH ); }
/*----------------------------------------------------------------------------*/ int main(void) { setupClock(); const struct Pin led = pinInit(LED_PIN); pinOutput(led, true); struct GpTimerPwmUnit * const pwmUnit = init(GpTimerPwmUnit, &pwmUnitConfig); assert(pwmUnit); struct Pwm * const pwmOutput = gpTimerPwmCreate(pwmUnit, OUTPUT_PIN); assert(pwmOutput); pwmSetDuration(pwmOutput, pwmGetResolution(pwmOutput) / 2); struct Timer * const counter = init(GpTimerCounter, &counterConfig); assert(counter); struct Timer * const timer = init(GpTimer, &timerConfig); assert(timer); timerSetOverflow(timer, 1000); bool event = false; timerSetCallback(timer, onTimerOverflow, &event); timerEnable(counter); pwmEnable(pwmOutput); timerEnable(timer); while (1) { while (!event) barrier(); event = false; const uint32_t period = timerGetValue(counter); timerSetValue(counter, 0); if (period >= 999 && period <= 1001) pinReset(led); else pinSet(led); } return 0; }