void StepperMotor::initialize(brain_pin_e stepPin, brain_pin_e directionPin, pin_output_mode_e directionPinMode, float reactionTime, int totalSteps, brain_pin_e enablePin, Logging *sharedLogger) { this->reactionTime = maxF(1, reactionTime); this->totalSteps = maxI(3, totalSteps); logger = sharedLogger; if (stepPin == GPIO_UNASSIGNED || directionPin == GPIO_UNASSIGNED) { return; } stepPort = getHwPort("step", stepPin); this->stepPin = getHwPin("step", stepPin); this->directionPinMode = directionPinMode; this->directionPin.initPin("stepper dir", directionPin, &this->directionPinMode); enablePort = getHwPort("enable", enablePin); this->enablePin = getHwPin("enable", enablePin); efiSetPadMode("stepper step", stepPin, PAL_MODE_OUTPUT_PUSHPULL); efiSetPadMode("stepper enable", enablePin, PAL_MODE_OUTPUT_PUSHPULL); palWritePad(this->enablePort, enablePin, true); // disable stepper // All pins must be 0 for correct hardware startup (e.g. stepper auto-disabling circuit etc.). palWritePad(this->stepPort, this->stepPin, false); this->directionPin.setValue(false); this->currentDirection = false; chThdCreateStatic(stThreadStack, sizeof(stThreadStack), NORMALPRIO, (tfunc_t) stThread, this); }
static msg_t stThread(StepperMotor *motor) { chRegSetThreadName("stepper"); palWritePad(motor->directionPort, motor->directionPin, false); // let's park the motor in a known position to begin with for (int i = 0; i < ST_COUNT; i++) { motor->pulse(); } while (true) { int targetPosition = motor->targetPosition; int currentPosition = motor->currentPosition; if (targetPosition == currentPosition) { chThdSleepMilliseconds(ST_DELAY_MS); continue; } bool_t isIncrementing = targetPosition > currentPosition; palWritePad(motor->directionPort, motor->directionPin, isIncrementing); if (isIncrementing) { motor->currentPosition++; } else { motor->currentPosition--; } motor->pulse(); } // let's part the motor in a known position to begin with // for (int i = 0; i < ST_COUNT / 2; i++) { // motor->pulse(); // } return 0; }
//----------------------------------------------------------------------------- static void lcd_HD44780_write(uint8_t data) { if (engineConfiguration->displayMode == DM_HD44780) { palWritePad(HD44780_PORT_DB7, HD44780_PIN_DB7, data & 0x80 ? 1 : 0); palWritePad(HD44780_PORT_DB6, HD44780_PIN_DB6, data & 0x40 ? 1 : 0); palWritePad(HD44780_PORT_DB5, HD44780_PIN_DB5, data & 0x20 ? 1 : 0); palWritePad(HD44780_PORT_DB4, HD44780_PIN_DB4, data & 0x10 ? 1 : 0); palSetPad(HD44780_PORT_E, HD44780_PIN_E); // En high lcdSleep(10); // enable pulse must be >450ns palClearPad(HD44780_PORT_E, HD44780_PIN_E); // En low lcdSleep(40); // commands need > 37us to settle } else { // LCD D4_pin -> P4 // LCD D5_pin -> P5 // LCD D6_pin -> P6 // LCD D7_pin -> P7 // LCD Pin RS -> P0 // LCD Pin RW -> P1 // LCD Pin E -> P2 i2cAcquireBus(&I2CD1); txbuf[0] = 4; i2cMasterTransmit(&I2CD1, LCD_PORT_EXP_ADDR, txbuf, 1, NULL, 0); lcdSleep(10); // enable pulse must be >450ns txbuf[0] = 0; i2cMasterTransmit(&I2CD1, LCD_PORT_EXP_ADDR, txbuf, 1, NULL, 0); i2cReleaseBus(&I2CD1); } }
static msg_t Th2(void *p) { (void)p; chRegSetThreadName("Th2"); while (TRUE) { /////DEVICE 2/////////// if(palReadPad(GPIO1_PORT, GPIO1_PAD) != PAL_HIGH) { palWritePad(GPIO22_PORT,GPIO22_PAD,PAL_HIGH); chSemWait(&mySemaphore); chprintf((BaseSequentialStream *)&SD1, "D2ON\r\n"); chSemSignal(&mySemaphore); }else{ palWritePad(GPIO22_PORT,GPIO22_PAD,PAL_LOW); chSemWait(&mySemaphore); chprintf((BaseSequentialStream *)&SD1, "D2OFF\r\n"); chSemSignal(&mySemaphore); } chThdSleepMilliseconds(1000); } return 0; }
void StepperMotor::pulse() { palWritePad(enablePort, enablePin, false); // ebable stepper palWritePad(stepPort, stepPin, true); chThdSleepMilliseconds(reactionTime); palWritePad(stepPort, stepPin, false); chThdSleepMilliseconds(reactionTime); palWritePad(enablePort, enablePin, true); // disable stepper }
void led_write(int num, int state) { switch (num) { case LED_RED: palWritePad(GPIOE, 0, state); break; case LED_GREEN: palWritePad(GPIOE, 1, state); break; default: break; } }
/** * Set's the value of the pin. On this layer the value is assigned as is, without any conversion. */ void setPinValue(OutputPin * outputPin, int electricalValue, int logicValue) { if (getLogicPinValue(outputPin) == logicValue) return; palWritePad(outputPin->port, outputPin->pin, electricalValue); outputPin->currentLogicValue = logicValue; }
//Release the SCCB -- requires the timer static void stopCondition(void){ //chSysLockFromIsr(); //Pull SDA Low palWritePad(CAM_CTL_PORT, CAM_SDA, 0); //Set SCL Low palWritePad(CAM_CTL_PORT, CAM_SCL, 0); gptPolledDelay(&GPTD3,CLK_DELAY); //SCL High palWritePad(CAM_CTL_PORT, CAM_SCL, 1); gptPolledDelay(&GPTD3,CLK_DELAY); //SDA High palWritePad(CAM_CTL_PORT, CAM_SDA, 1); //chSysUnlockFromIsr(); return; }
//Initiate SCCB start condition -- requires the timer static void startCondition(void){ //chSysLockFromIsr(); //Pull SDA SCL High palWritePad(CAM_CTL_PORT, CAM_SDA, 1); palWritePad(CAM_CTL_PORT, CAM_SCL, 1); //Wait gptPolledDelay(&GPTD3,CLK_DELAY); //Data Low palWritePad(CAM_CTL_PORT, CAM_SDA, 0); gptPolledDelay(&GPTD3,CLK_DELAY); //Clock Low palWritePad(CAM_CTL_PORT, CAM_SCL, 0); gptPolledDelay(&GPTD3,CLK_DELAY); //chSysUnlockFromIsr(); return; }
void DispayAbortErr(int err) { DBGPRINTCHAR('0' + err); #if AXOLOTICONTROL LCD_drawStringN(0, 5, "error code:", 128); LCD_drawNumber3D(0, 6, (int)err); refresh_LCD(); #endif // blink red slowly, green off palWritePad(LED1_PORT, LED1_PIN, 0); int i = 10; while (i--) { palWritePad(LED2_PORT, LED2_PIN, 1); chThdSleepMilliseconds(1000); palWritePad(LED2_PORT, LED2_PIN, 0); chThdSleepMilliseconds(1000); } NVIC_SystemReset(); }
void setCANLed(unsigned iface_index, bool state) { switch (iface_index) { case 0: { palWritePad(GPIO_PORT_LED_CAN1, GPIO_PIN_LED_CAN1, std::uint8_t(state)); break; } case 1: { palWritePad(GPIO_PORT_LED_CAN2, GPIO_PIN_LED_CAN2, std::uint8_t(state)); break; } default: { break; } } }
//----------------------------------------------------------------------------- static void lcd_HD44780_write(uint8_t data) { if (engineConfiguration->displayMode == DM_HD44780) { palWritePad(getHwPort(boardConfiguration->HD44780_db7), getHwPin(boardConfiguration->HD44780_db7), data & 0x80 ? 1 : 0); palWritePad(getHwPort(boardConfiguration->HD44780_db6), getHwPin(boardConfiguration->HD44780_db6), data & 0x40 ? 1 : 0); palWritePad(getHwPort(boardConfiguration->HD44780_db5), getHwPin(boardConfiguration->HD44780_db5), data & 0x20 ? 1 : 0); palWritePad(getHwPort(boardConfiguration->HD44780_db4), getHwPin(boardConfiguration->HD44780_db4), data & 0x10 ? 1 : 0); palSetPad(getHwPort(boardConfiguration->HD44780_e), getHwPin(boardConfiguration->HD44780_e)); // En high lcdSleep(10); // enable pulse must be >450ns palClearPad(getHwPort(boardConfiguration->HD44780_e), getHwPin(boardConfiguration->HD44780_e)); // En low lcdSleep(40); // commands need > 37us to settle } else { // LCD D4_pin -> P4 // LCD D5_pin -> P5 // LCD D6_pin -> P6 // LCD D7_pin -> P7 // LCD Pin RS -> P0 // LCD Pin RW -> P1 // LCD Pin E -> P2 // todo: finish all this stuff // i2cAcquireBus(&I2CD1); // // txbuf[0] = 4; // i2cMasterTransmit(&I2CD1, LCD_PORT_EXP_ADDR, txbuf, 1, NULL, 0); // lcdSleep(10); // enable pulse must be >450ns // // txbuf[0] = 0; // i2cMasterTransmit(&I2CD1, LCD_PORT_EXP_ADDR, txbuf, 1, NULL, 0); // // i2cReleaseBus(&I2CD1); } }
// move to the given setpoint void motionTarget (const Setpoint& s) { LPC_TMR32B0->MR3 = ~0; // set timer count to max, so it won't change now // determine target step to end on, rounding from a 24.8 to a 24.0 int int target = posToStep(s.position); if (s.relative) target += motionPosition(); // enforce soft position limits if (target < posToStep(motion.params.minPos)) { target = posToStep(motion.params.minPos); motion.errors |= 1<<F_HITMIN; // bumped into min position limit } if (target > posToStep(motion.params.maxPos)) { target = posToStep(motion.params.maxPos); motion.errors |= 1<<F_HITMAX; // bumped into max position limit } // set the next target int stepDiff = target - motionPosition(); motion.direction = stepDiff > 0 ? 1 : -1; motion.stepsToGo = stepDiff * motion.direction; motion.targetStep = target; if (motion.stepsToGo > 0) { uint32_t clocks = MHZ * USPT * s.time + motion.residue; uint32_t rate = (clocks + motion.stepsToGo / 2) / motion.stepsToGo; motion.residue = clocks - rate * motion.stepsToGo; if (rate < MHZ * 10) { // enforce a soft timer rate limit rate = MHZ * 10; // at least 10 µs, i.e. max 100 KHz motion.errors |= 1<<F_TOOFAST; // rate limiting took place } // TODO: could check that rate > TC, i.e. no overrun has occurred LPC_TMR32B0->MR3 = rate; palWritePad(GPIO1, GPIO1_MOTOR_DIR, stepDiff > 0 ? 1 : 0); palClearPad(GPIO3, GPIO3_MOTOR_EN); // active low, on LPC_TMR32B0->TCR = 1; // start timer if it wasn't running while (motion.stepsToGo > 0) // move! chThdYield(); // uses idle polling } else if (s.time > 0) { LPC_TMR32B0->TCR = 0; // stop timer chThdSleepMilliseconds(s.time); // dwell } if (s.velocity == 0) palSetPad(GPIO3, GPIO3_MOTOR_EN); // active low, off }
void lcd_HD44780_init(Logging *sharedLogger) { logger = sharedLogger; addConsoleAction("lcdinfo", lcdInfo); if (engineConfiguration->displayMode > DM_HD44780_OVER_PCF8574) { firmwareError("Unexpected displayMode %d", engineConfiguration->displayMode); return; } printMsg(logger, "lcd_HD44780_init %d", engineConfiguration->displayMode); if (engineConfiguration->displayMode == DM_HD44780) { // initialize hardware lines mySetPadMode2("lcd RS", boardConfiguration->HD44780_rs, PAL_MODE_OUTPUT_PUSHPULL); mySetPadMode2("lcd E", boardConfiguration->HD44780_e, PAL_MODE_OUTPUT_PUSHPULL); mySetPadMode2("lcd DB4", boardConfiguration->HD44780_db4, PAL_MODE_OUTPUT_PUSHPULL); mySetPadMode2("lcd DB6", boardConfiguration->HD44780_db5, PAL_MODE_OUTPUT_PUSHPULL); mySetPadMode2("lcd DB7", boardConfiguration->HD44780_db6, PAL_MODE_OUTPUT_PUSHPULL); mySetPadMode2("lcd DB8", boardConfiguration->HD44780_db7, PAL_MODE_OUTPUT_PUSHPULL); // and zero values palWritePad(getHwPort(boardConfiguration->HD44780_rs), getHwPin(boardConfiguration->HD44780_rs), 0); palWritePad(getHwPort(boardConfiguration->HD44780_e), getHwPin(boardConfiguration->HD44780_e), 0); palWritePad(getHwPort(boardConfiguration->HD44780_db4), getHwPin(boardConfiguration->HD44780_db4), 0); palWritePad(getHwPort(boardConfiguration->HD44780_db5), getHwPin(boardConfiguration->HD44780_db5), 0); palWritePad(getHwPort(boardConfiguration->HD44780_db6), getHwPin(boardConfiguration->HD44780_db6), 0); palWritePad(getHwPort(boardConfiguration->HD44780_db7), getHwPin(boardConfiguration->HD44780_db7), 0); } chThdSleepMilliseconds(20); // LCD needs some time to wake up lcd_HD44780_write(LCD_HD44780_RESET); // reset 1x chThdSleepMilliseconds(1); lcd_HD44780_write(LCD_HD44780_RESET); // reset 2x lcd_HD44780_write(LCD_HD44780_RESET); // reset 3x lcd_HD44780_write(LCD_HD44780_4_BIT_BUS); // 4 bit, 2 line chThdSleepMicroseconds(40); lcd_HD44780_write(LCD_HD44780_4_BIT_BUS); // 4 bit, 2 line lcd_HD44780_write(0x80); chThdSleepMicroseconds(40); lcd_HD44780_write_command(0x08); // display and cursor control chThdSleepMicroseconds(40); lcd_HD44780_write_command(LCD_HD44780_DISPLAY_CLEAR); chThdSleepMilliseconds(2); lcd_HD44780_write_command(LCD_HD44780_SHIFT_CURSOR_RIGHT); chThdSleepMilliseconds(2); lcd_HD44780_write_command(LCD_HD44780_DISPLAY_ON); lcd_HD44780_set_position(0, 0); printMsg(logger, "lcd_HD44780_init() done"); }
static msg_t ivThread(int param) { (void) param; chRegSetThreadName("board test blinking"); int value = 0; while (TRUE) { chThdSleepMilliseconds(250); value = 1 - value; GPIO_TypeDef *hwPort = getHwPort(currentPin); uint32_t hwPin = getHwPin(currentPin); palWritePad(hwPort, hwPin, value); } #if defined __GNUC__ return 0; #endif }
void DigitalPlatform::set(std::uint8_t ch, bool on) { switch (ch) { case 0: palWritePad(GPIOA, 4, on); break; //case 1: palWritePad(GPIOA, 5, on); break; case 2: palWritePad(GPIOC, 4, on); break; case 3: palWritePad(GPIOC, 5, on); break; case 4: palWritePad(GPIOA, 12, on); break; case 5: palWritePad(GPIOA, 15, on); break; case 6: palWritePad(GPIOB, 2, on); break; default: break; } }
void lcd_HD44780_init(void) { initLogging(&logger, "HD44780 driver"); addConsoleAction("lcdinfo", lcdInfo); if (engineConfiguration->displayMode == DM_HD44780) { mySetPadMode("lcd RS", HD44780_PORT_RS, HD44780_PIN_RS, PAL_MODE_OUTPUT_PUSHPULL); mySetPadMode("lcd E", HD44780_PORT_E, HD44780_PIN_E, PAL_MODE_OUTPUT_PUSHPULL); mySetPadMode("lcd DB4", HD44780_PORT_DB4, HD44780_PIN_DB4, PAL_MODE_OUTPUT_PUSHPULL); mySetPadMode("lcd DB6", HD44780_PORT_DB5, HD44780_PIN_DB5, PAL_MODE_OUTPUT_PUSHPULL); mySetPadMode("lcd DB7", HD44780_PORT_DB6, HD44780_PIN_DB6, PAL_MODE_OUTPUT_PUSHPULL); mySetPadMode("lcd DB8", HD44780_PORT_DB7, HD44780_PIN_DB7, PAL_MODE_OUTPUT_PUSHPULL); palWritePad(HD44780_PORT_RS, HD44780_PIN_RS, 0); palWritePad(HD44780_PORT_E, HD44780_PIN_E, 0); palWritePad(HD44780_PORT_DB4, HD44780_PIN_DB4, 0); palWritePad(HD44780_PORT_DB5, HD44780_PIN_DB5, 0); palWritePad(HD44780_PORT_DB6, HD44780_PIN_DB6, 0); palWritePad(HD44780_PORT_DB7, HD44780_PIN_DB7, 0); } // LCD needs some time to wake up chThdSleepMilliseconds(50); lcd_HD44780_write(LCD_2X16_RESET); chThdSleepMilliseconds(1); lcd_HD44780_write(0x30); lcd_HD44780_write(LCD_2X16_4_BIT_BUS); // 4 bit, 2 line chThdSleepMicroseconds(40); lcd_HD44780_write(LCD_2X16_4_BIT_BUS); // 4 bit, 2 line lcd_HD44780_write(0x80); chThdSleepMicroseconds(40); lcd_HD44780_write(0x00); // display and cursor control lcd_HD44780_write(0xC0); chThdSleepMicroseconds(40); lcd_HD44780_write(0x00); // display clear lcd_HD44780_write(0x01); chThdSleepMilliseconds(2); lcd_HD44780_write(0x00); // entry mode set lcd_HD44780_write(0x60); lcd_HD44780_set_position(0, 0); lcd_HD44780_print_string("rusefi here\n"); lcd_HD44780_print_string(__DATE__); }
int hardwareSetPins(int *arrayOfPinLocations, int * arrayOfPinsToSet) { int i = 0; int logic = FALSE; while(arrayOfPinLocations[i] !=END_PIN&&i<NUM_OF_PIN) { chprintf(&SD1,"%d,",i); int j = 0; logic = FALSE; while(arrayOfPinsToSet[j]!=END_PIN &&j<NUM_OF_PIN) { if(arrayOfPinLocations[i] ==arrayOfPinsToSet[j]) { logic=TRUE; } j++; } palWritePad(hwPin[arrayOfPinLocations[i]].pinPort, hwPin[arrayOfPinLocations[i]].pinNumber,logic); i++; } }
/* Main thread */ int main(void) { /* ChibiOS/RT init */ halInit(); #if defined(F042) SYSCFG->CFGR1 |= SYSCFG_CFGR1_PA11_PA12_RMP; /* remap pins to USB */ #endif /* F042 */ chSysInit(); palSetPad(LED_GPIO, LED_PIN); chThdSleepMilliseconds(400); palClearPad(LED_GPIO, LED_PIN); /* Init USB */ init_usb_driver(&USB_DRIVER); /* Start blinking */ chThdCreateStatic(waBlinkerThread, sizeof(waBlinkerThread), NORMALPRIO, blinkerThread, NULL); /* Wait until the USB is active */ while(USB_DRIVER.state != USB_ACTIVE) chThdSleepMilliseconds(1000); chThdSleepMilliseconds(500); /* Start the button thread */ palSetPadMode(BUTTON_GPIO, BUTTON_PIN, BUTTON_MODE); chThdCreateStatic(waButtonThread, sizeof(waButtonThread), NORMALPRIO, buttonThread, NULL); /* Main loop */ while(true) { chThdSleepMilliseconds(200); /* caps lock led status */ #if defined(LED2_GPIO) palWritePad(LED2_GPIO, LED2_PIN, ((keyboard_leds() & 2) == 2)); #endif } }
//Idle the SCCB static void idleState(void){ palWritePad(CAM_CTL_PORT, CAM_SCL, 1); palWritePad(CAM_CTL_PORT, CAM_SDA, 1); return; }
static void cmd_smart_cc3000(BaseSequentialStream *chp, int argc, char *argv[]) { long rval; (void)argv; if(argc > 0) { chprintf(chp, "Usage: setup\r\n"); return; } chprintf(chp, "Disconnecting "); wlan_disconnect(); while(cc3000AsyncData.connected == 1) { chprintf(chp, "."); } chprintf(chp, "done!\r\n"); chprintf(chp, "Disabling auto connect policy ...\r\n"); /* Set connection policy to disable */ if ((rval = wlan_ioctl_set_connection_policy(DISABLE, DISABLE, DISABLE)) != 0) { chprintf(chp, "Error disabling auto connect policy ...\r\n"); return; } /* Delete all profiles */ chprintf(chp, "Deleting all profiles ...\r\n"); if ((rval = wlan_ioctl_del_profile(255)) != 0) { chprintf(chp, "Error deleting profiles ...\r\n"); return; } chprintf(chp, "Creating AES keys ...\r\n"); nvmem_create_entry(NVMEM_AES128_KEY_FILEID, AES128_KEY_SIZE); aes_write_key((UINT8 *) AES_KEY); // Set the smart config prefix chprintf(chp, "Setting smart config prefix ...\r\n"); if((rval = wlan_smart_config_set_prefix(smartConfigPrefix)) != 0) { chprintf(chp, "Error setting smart config prefix ... \r\n"); return; } chprintf(chp, "Starting CC3000 SmartConfig ...\r\n"); if((rval = wlan_smart_config_start(0)) != 0) { chprintf(chp, "Error starting smart config ...\r\n"); return; } chprintf(chp, "Waiting for SmartConfig to finish ...\r\n"); /* Wait until smart config is finished */ while(cc3000AsyncData.smartConfigFinished == 0) { // We blink the led here .. the thread process // will set this to PAL_LOW (since we are disconnected) palWritePad(CON_LED_PORT, CON_LED_PIN, PAL_HIGH); chThdSleep(MS2ST(200)); } chprintf(chp, "Smart config packet received ...\r\n"); /* Re enable auto connect policy */ if ((rval = wlan_ioctl_set_connection_policy(DISABLE, DISABLE, ENABLE)) != 0) { chprintf(chp, "Error setting auto connect policy ...\r\n"); return; } /* Restart wlan */ wlan_stop(); chprintf(chp, "Reconnecting ...\r\n"); chThdSleep(MS2ST(2000)); wlan_start(0); /* No need to call connect, hopefully auto connect policy * can connect to our AP now **/ chprintf(chp, "Waiting for connection to AP ...\r\n"); while (cc3000AsyncData.dhcp.present != 1) { chThdSleep(MS2ST(5)); } show_cc3_dhcp_info(chp); mdnsAdvertiser(1, deviceName, strlen(deviceName)); }
void StepperMotor::pulse() { palWritePad(stepPort, stepPin, true); chThdSleepMilliseconds(ST_DELAY_MS); palWritePad(stepPort, stepPin, false); chThdSleepMilliseconds(ST_DELAY_MS); }
void setDiag(int value) { print("Setting diag: %d\r\n", value); palWritePad(DIAG_PORT, DIAG_PIN, value); }
//Write a byte, MSB first, with don't-care at the end -- requires the timer static void writeByte(uint8_t byte){ //chSysLockFromIsr(); //MSB Bit 7 gptPolledDelay(&GPTD3,CLK_DELAY); palWritePad(CAM_CTL_PORT, CAM_SCL, 0); palWritePad(CAM_CTL_PORT, CAM_SDA, (byte & 0x80)>>7); gptPolledDelay(&GPTD3,CLK_DELAY); palWritePad(CAM_CTL_PORT, CAM_SCL, 1); //Bit 6 gptPolledDelay(&GPTD3,CLK_DELAY); palWritePad(CAM_CTL_PORT, CAM_SCL, 0); palWritePad(CAM_CTL_PORT, CAM_SDA, (byte & 0x40)>>6); gptPolledDelay(&GPTD3,CLK_DELAY); palWritePad(CAM_CTL_PORT, CAM_SCL, 1); //Bit 5 gptPolledDelay(&GPTD3,CLK_DELAY); palWritePad(CAM_CTL_PORT, CAM_SCL, 0); palWritePad(CAM_CTL_PORT, CAM_SDA, (byte & 0x20)>>5); gptPolledDelay(&GPTD3,CLK_DELAY); palWritePad(CAM_CTL_PORT, CAM_SCL, 1); //Bit 4 gptPolledDelay(&GPTD3,CLK_DELAY); palWritePad(CAM_CTL_PORT, CAM_SCL, 0); palWritePad(CAM_CTL_PORT, CAM_SDA, (byte & 0x10)>>4); gptPolledDelay(&GPTD3,CLK_DELAY); palWritePad(CAM_CTL_PORT, CAM_SCL, 1); //Bit 3 gptPolledDelay(&GPTD3,CLK_DELAY); palWritePad(CAM_CTL_PORT, CAM_SCL, 0); palWritePad(CAM_CTL_PORT, CAM_SDA, (byte & 0x08)>>3); gptPolledDelay(&GPTD3,CLK_DELAY); palWritePad(CAM_CTL_PORT, CAM_SCL, 1); //Bit 2 gptPolledDelay(&GPTD3,CLK_DELAY); palWritePad(CAM_CTL_PORT, CAM_SCL, 0); palWritePad(CAM_CTL_PORT, CAM_SDA, (byte & 0x04)>>2); gptPolledDelay(&GPTD3,CLK_DELAY); palWritePad(CAM_CTL_PORT, CAM_SCL, 1); //Bit 1 gptPolledDelay(&GPTD3,CLK_DELAY); palWritePad(CAM_CTL_PORT, CAM_SCL, 0); palWritePad(CAM_CTL_PORT, CAM_SDA, (byte & 0x02)>>1); gptPolledDelay(&GPTD3,CLK_DELAY); palWritePad(CAM_CTL_PORT, CAM_SCL, 1); //Bit 0 gptPolledDelay(&GPTD3,CLK_DELAY); palWritePad(CAM_CTL_PORT, CAM_SCL, 0); palWritePad(CAM_CTL_PORT, CAM_SDA, (byte & 0x01) ); gptPolledDelay(&GPTD3,CLK_DELAY); palWritePad(CAM_CTL_PORT, CAM_SCL, 1); //9th Don't Care bit gptPolledDelay(&GPTD3,CLK_DELAY); palWritePad(CAM_CTL_PORT, CAM_SCL, 0); gptPolledDelay(&GPTD3,CLK_DELAY); //Deassert don't care palSetPadMode(CAM_CTL_PORT, CAM_SDA, PAL_MODE_INPUT ); palWritePad(CAM_CTL_PORT, CAM_SCL, 1); gptPolledDelay(&GPTD3,CLK_DELAY); //chSysUnlockFromIsr(); //Re-assert the SDA palSetPadMode(CAM_CTL_PORT, CAM_SDA, PAL_MODE_OUTPUT_PUSHPULL | PAL_STM32_OSPEED_LOWEST ); //Done with byte return; }
void setStatusLed(bool state) { palWritePad(GPIO_PORT_LED_STATUS, GPIO_PIN_LED_STATUS, std::uint8_t(state)); }
int main(void) { DMA1_Stream0->CR=0; DMA1_Stream1->CR=0; DMA1_Stream2->CR=0; DMA1_Stream3->CR=0; DMA1_Stream4->CR=0; DMA1_Stream5->CR=0; DMA1_Stream6->CR=0; DMA1_Stream7->CR=0; DMA2_Stream0->CR=0; DMA2_Stream1->CR=0; DMA2_Stream2->CR=0; DMA2_Stream3->CR=0; DMA2_Stream4->CR=0; DMA2_Stream5->CR=0; DMA2_Stream6->CR=0; DMA2_Stream7->CR=0; palClearPad(GPIOD,7); // disable USBH power // copy vector table memcpy((char *)0x20000000, (const char *)&_vectors, 0x200); // remap SRAM1 to 0x00000000 SYSCFG->MEMRMP |= 0x03; // FMC_SDRAMDeInit(0); // RCC->AHB3RSTR |= 1; //RCC_AHB3RSTR_FMCRST RCC->AHB3ENR |= 1; //RCC_AHB3ENR_FMCEN; // HAL_DeInit(); // HAL_Init(); watchdog_feed(); halInit(); // float usb inputs, hope the host notices detach... palSetPadMode(GPIOA, 11, PAL_MODE_INPUT); palSetPadMode(GPIOA, 12, PAL_MODE_INPUT); // setup LEDs palSetPadMode(LED1_PORT,LED1_PIN,PAL_MODE_OUTPUT_PUSHPULL); palSetPad(LED1_PORT,LED1_PIN); #ifdef LED2_PIN palSetPadMode(LED2_PORT,LED2_PIN,PAL_MODE_OUTPUT_PUSHPULL); #endif chSysInit(); watchdog_feed(); configSDRAM(); #ifdef SERIALDEBUG // SD2 for serial debug output palSetPadMode(GPIOA, 3, PAL_MODE_ALTERNATE(7) | PAL_MODE_INPUT); // RX palSetPadMode(GPIOA, 2, PAL_MODE_OUTPUT_PUSHPULL); // TX palSetPadMode(GPIOA, 2, PAL_MODE_ALTERNATE(7)); // TX // 115200 baud static const SerialConfig sd2Cfg = {115200, 0, 0, 0}; sdStart(&SD2, &sd2Cfg); #endif DBGPRINTCHAR('a'); uint32_t pbuf[16]; SDRAM_ReadBuffer(&pbuf[0], 0 + 0x050000, 16); DBGPRINTCHAR('x'); watchdog_feed(); uint32_t *sdram32 = (uint32_t *)SDRAM_BANK_ADDR; uint8_t *sdram8 = (uint8_t *)SDRAM_BANK_ADDR; if ((sdram8[0] != 'f') || (sdram8[1] != 'l') || (sdram8[2] != 'a') || (sdram8[3] != 's') || (sdram8[4] != 'c') || (sdram8[5] != 'o') || (sdram8[6] != 'p') || (sdram8[7] != 'y')) { DispayAbortErr(1); } DBGPRINTCHAR('b'); uint32_t flength = sdram32[2]; uint32_t fcrc = sdram32[3]; if (flength > 1 * 1024 * 1024) { DispayAbortErr(2); } DBGPRINTCHAR('c'); DBGPRINTHEX(flength); uint32_t ccrc = CalcCRC32((uint8_t *)(SDRAM_BANK_ADDR + 0x010), flength); DBGPRINTCHAR('d'); DBGPRINTHEX(ccrc); DBGPRINTHEX(fcrc); if (ccrc != fcrc) { DispayAbortErr(3); } DBGPRINTCHAR('e'); // unlock sequence FLASH->KEYR = 0x45670123; FLASH->KEYR = 0xCDEF89AB; uint32_t i; for (i = 0; i < 12; i++) { flash_Erase_sector(i); LCD_drawStringN(0, 3, "Erased sector", 128); LCD_drawNumber3D(80, 3, i); refresh_LCD(); palWritePad(LED2_PORT,LED2_PIN,1); chThdSleepMilliseconds(100); palWritePad(LED2_PORT,LED2_PIN,0); DBGPRINTCHAR('f'); DBGPRINTHEX(i); } DBGPRINTCHAR('g'); DBGPRINTHEX(flength); ccrc = CalcCRC32((uint8_t *)(SDRAM_BANK_ADDR + 0x010), flength); DBGPRINTCHAR('h'); DBGPRINTHEX(ccrc); DBGPRINTHEX(fcrc); if (ccrc != fcrc) { DispayAbortErr(4); } DBGPRINTCHAR('i'); int destptr = FLASH_BASE_ADDR; // flash base adress uint32_t *srcptr = (uint32_t *)(SDRAM_BANK_ADDR + 0x010); // sdram base adress + header offset for (i = 0; i < (flength + 3) / 4; i++) { uint32_t d = *srcptr; flash_ProgramWord(destptr, d); if ((FLASH->SR != 0) && (FLASH->SR != 1)) { DBGPRINTCHAR('z'); DBGPRINTHEX(FLASH->SR); } // DBGPRINTHEX(f); if ((i & 0xFFF) == 0) { palWritePad(LED2_PORT,LED2_PIN,1); chThdSleepMilliseconds(100); palWritePad(LED2_PORT,LED2_PIN,0); DBGPRINTCHAR('j'); DBGPRINTHEX(destptr); DBGPRINTHEX(*(srcptr)); } destptr += 4; srcptr++; } DBGPRINTCHAR('k'); ccrc = CalcCRC32((uint8_t *)(FLASH_BASE_ADDR), flength); DBGPRINTCHAR('l'); DBGPRINTHEX(ccrc); DBGPRINTHEX(fcrc); if (ccrc != fcrc) { DispayAbortErr(5); } DBGPRINTCHAR('\r'); DBGPRINTCHAR('\n'); DBGPRINTCHAR('S'); DBGPRINTCHAR('U'); DBGPRINTCHAR('C'); DBGPRINTCHAR('C'); DBGPRINTCHAR('E'); DBGPRINTCHAR('S'); DBGPRINTCHAR('S'); DBGPRINTCHAR('\r'); DBGPRINTCHAR('\n'); chThdSleepMilliseconds(1000); NVIC_SystemReset(); return 0; }
void GPIO_Stepper_Enable(uint8_t En) { palWritePad( STEPPER_PORT, STEPPER_EN_PIN, En?PAL_LOW:PAL_HIGH);/* Note that Allegro uses inverted logic levels */ }
void GPIO_Stepper_Dir(uint8_t Dir) { #ifdef STEPPER_INVERTED_DIR Dir=!Dir; #endif palWritePad( STEPPER_PORT, STEPPER_DIR_PIN, Dir?PAL_HIGH:PAL_LOW); }
static uint8_t readByte(void){ //chSysLockFromIsr(); //Configure input pad uint8_t byte = 0; palSetPadMode(CAM_CTL_PORT, CAM_SDA, PAL_MODE_INPUT ); gptPolledDelay(&GPTD3,CLK_DELAY); //MSB Bit 7 palWritePad(CAM_CTL_PORT, CAM_SCL, 0); gptPolledDelay(&GPTD3,CLK_DELAY); palWritePad(CAM_CTL_PORT, CAM_SCL, 1); gptPolledDelay(&GPTD3,CLK_DELAY); byte |= ( palReadPad(CAM_CTL_PORT, CAM_SDA) )<<7; //Bit 6 palWritePad(CAM_CTL_PORT, CAM_SCL, 0); gptPolledDelay(&GPTD3,CLK_DELAY); palWritePad(CAM_CTL_PORT, CAM_SCL, 1); gptPolledDelay(&GPTD3,CLK_DELAY); byte |= ( palReadPad(CAM_CTL_PORT, CAM_SDA) )<<6; //Bit 5 palWritePad(CAM_CTL_PORT, CAM_SCL, 0); gptPolledDelay(&GPTD3,CLK_DELAY); palWritePad(CAM_CTL_PORT, CAM_SCL, 1); gptPolledDelay(&GPTD3,CLK_DELAY); byte |= ( palReadPad(CAM_CTL_PORT, CAM_SDA) )<<5; //Bit 4 palWritePad(CAM_CTL_PORT, CAM_SCL, 0); gptPolledDelay(&GPTD3,CLK_DELAY); palWritePad(CAM_CTL_PORT, CAM_SCL, 1); gptPolledDelay(&GPTD3,CLK_DELAY); byte |= ( palReadPad(CAM_CTL_PORT, CAM_SDA) )<<4; //Bit 3 palWritePad(CAM_CTL_PORT, CAM_SCL, 0); gptPolledDelay(&GPTD3,CLK_DELAY); palWritePad(CAM_CTL_PORT, CAM_SCL, 1); gptPolledDelay(&GPTD3,CLK_DELAY); byte |= ( palReadPad(CAM_CTL_PORT, CAM_SDA) )<<3; //Bit 2 palWritePad(CAM_CTL_PORT, CAM_SCL, 0); gptPolledDelay(&GPTD3,CLK_DELAY); palWritePad(CAM_CTL_PORT, CAM_SCL, 1); gptPolledDelay(&GPTD3,CLK_DELAY); byte |= ( palReadPad(CAM_CTL_PORT, CAM_SDA) )<<2; //Bit 1 palWritePad(CAM_CTL_PORT, CAM_SCL, 0); gptPolledDelay(&GPTD3,CLK_DELAY); palWritePad(CAM_CTL_PORT, CAM_SCL, 1); gptPolledDelay(&GPTD3,CLK_DELAY); byte |= ( palReadPad(CAM_CTL_PORT, CAM_SDA) )<<1; //Bit 0 palWritePad(CAM_CTL_PORT, CAM_SCL, 0); gptPolledDelay(&GPTD3,CLK_DELAY); palWritePad(CAM_CTL_PORT, CAM_SCL, 1); gptPolledDelay(&GPTD3,CLK_DELAY); byte |= ( palReadPad(CAM_CTL_PORT, CAM_SDA) ); //9th Don't Care Byte palWritePad(CAM_CTL_PORT, CAM_SCL, 0); //Dive to 1 per datasheet palSetPadMode(CAM_CTL_PORT, CAM_SDA, PAL_MODE_OUTPUT_PUSHPULL | PAL_STM32_OSPEED_LOWEST ); palWritePad(CAM_CTL_PORT, CAM_SDA, 1); gptPolledDelay(&GPTD3,CLK_DELAY); palWritePad(CAM_CTL_PORT, CAM_SCL, 1); gptPolledDelay(&GPTD3,CLK_DELAY); //chSysUnlockFromIsr(); //Re-assert the SDA palSetPadMode(CAM_CTL_PORT, CAM_SDA, PAL_MODE_OUTPUT_OPENDRAIN | PAL_STM32_OSPEED_LOWEST ); //Done with byte return byte; }
void Rf24ChibiosIo::ce(bool level) { palWritePad(ce_port, ce_pad, level); }