void Lcd_t::Init(void) { BckLt.Init(LCD_BCKLT_GPIO, LCD_BCKLT_PIN, LCD_BCKLT_TMR, LCD_BCKLT_CHNL, LCD_TOP_BRIGHTNESS); // Remap Timer15 to PB14 & PB15 AFIO->MAPR2 |= 0x00000001; // ==== GPIOs ==== // Configure LCD_XRES, LCD_XCS, LCD_SCLK & LCD_SDA as Push-Pull output PinSetupOut(LCD_GPIO, LCD_XRES, omPushPull); PinSetupOut(LCD_GPIO, LCD_XRES, omPushPull); PinSetupOut(LCD_GPIO, LCD_XCS, omPushPull); PinSetupOut(LCD_GPIO, LCD_SCLK, omPushPull); PinSetupOut(LCD_GPIO, LCD_SDA, omPushPull); // ========================= Init LCD ====================================== SCLK_Lo(); XCS_Hi(); // Reset display XRES_Lo(); chThdSleepMilliseconds(7); XRES_Hi(); WriteCmd(0xAF); // display ON // Reset display again XRES_Lo(); chThdSleepMilliseconds(7); XRES_Hi(); chThdSleepMilliseconds(7); // Initial commands WriteCmd(0xAF); // display ON WriteCmd(0xA4); // Set normal display mode WriteCmd(0x2F); // Charge pump on WriteCmd(0x40); // Set start row address = 0 WriteCmd(0xC8); // Mirror Y axis //WriteCmd(0xA1); // Mirror X axis // Set x=0, y=0 WriteCmd(0xB0); // Y axis initialization WriteCmd(0x10); // X axis initialisation1 WriteCmd(0x00); // X axis initialisation2 Cls(); // clear LCD buffer // ====================== Switch to USART + DMA ============================ PinSetupAlterFuncOutput(LCD_GPIO, LCD_SCLK, omPushPull); PinSetupAlterFuncOutput(LCD_GPIO, LCD_SDA, omPushPull); // Workaround hardware bug with disabled CK3 when SPI2 is enabled SPI2->CR2 |= SPI_CR2_SSOE; // ==== USART init ==== clock enabled, idle low, first edge, enable last bit pulse rccEnableUSART3(FALSE); USART3->CR1 = USART_CR1_UE; // Enable USART3->BRR = Clk.APB1FreqHz / LCD_UART_SPEED; USART3->CR2 = USART_CR2_CLKEN | USART_CR2_LBCL; // Enable clock, enable last bit clock USART3->CR1 = USART_CR1_UE | USART_CR1_M | USART_CR1_TE; USART3->CR3 = USART_CR3_DMAT; // Enable DMA at transmitter // DMA dmaStreamAllocate (LCD_DMA, IRQ_PRIO_LOW, nullptr, NULL); dmaStreamSetPeripheral(LCD_DMA, &USART3->DR); dmaStreamSetMemory0 (LCD_DMA, IBuf); dmaStreamSetTransactionSize(LCD_DMA, LCD_VIDEOBUF_SIZE); dmaStreamSetMode (LCD_DMA, LCD_DMA_TX_MODE); // Start transmission XCS_Lo(); dmaStreamEnable(LCD_DMA); }
// Init GPIO for Power and Reset to the card HW static void card_gpio_init() { // gpio_enable_pin(CARD_PWR_PIN, GPIO_MODE_OUT); PinSetupOut(1, 22); PWR_OFF(); // gpio_enable_pin(CARD_RST_PIN, GPIO_MODE_OUT); PinSetupOut(1, 24); RST_LO(); }
// ================================== i2c_t ==================================== void i2c_t::Init(GPIO_TypeDef *PGPIO, uint16_t AScl, uint16_t ASda) { // Copy init data GPIO = PGPIO; Scl = AScl; Sda = ASda; // Setup pins PinSetupOut(GPIO, Scl, omOpenDrain, pudNone, ps100MHz); PinSetupOut(GPIO, Sda, omOpenDrain, pudNone, ps100MHz); SclHi(); SdaHi(); }
uint8_t rLevel1_t::Init() { #ifdef DBG_PINS PinSetupOut(DBG_GPIO1, DBG_PIN1, omPushPull); PinSetupOut(DBG_GPIO2, DBG_PIN2, omPushPull); #endif // Init radioIC if(CC.Init() == OK) { CC.SetTxPower(CC_Pwr0dBm); CC.SetPktSize(RPKT_LEN); // Thread PThd = chThdCreateStatic(warLvl1Thread, sizeof(warLvl1Thread), HIGHPRIO, (tfunc_t)rLvl1Thread, NULL); return OK; } else return FAILURE; }
void cc1101_t::Init() { // ==== GPIO ==== PinSetupOut (GPIOA, CC_CS, omPushPull, pudNone); PinSetupAlterFunc(GPIOA, CC_SCK, omPushPull, pudNone, AF5); PinSetupAlterFunc(GPIOA, CC_MISO, omPushPull, pudNone, AF5); PinSetupAlterFunc(GPIOA, CC_MOSI, omPushPull, pudNone, AF5); PinSetupIn (GPIOA, CC_GDO0, pudNone); PinSetupIn (GPIOA, CC_GDO2, pudNone); CsHi(); // ==== SPI ==== MSB first, master, SCK idle low, Baudrate=f/2 rccEnableSPI1(FALSE); // NoCRC, FullDuplex, 8bit, MSB, Baudrate, Master, ClkLowIdle(CPOL=0), // FirstEdge(CPHA=0), NSS software controlled and is 1 CC_SPI->CR1 = SPI_CR1_SSM | SPI_CR1_SSI | SPI_CR1_MSTR; CC_SPI->CR2 = 0; CC_SPI->I2SCFGR &= ~((uint16_t)SPI_I2SCFGR_I2SMOD); CC_SPI->CR1 |= SPI_CR1_SPE; // Enable SPI // ==== Init CC ==== CReset(); FlushRxFIFO(); RfConfig(); // ==== IRQ ==== rccEnableAPB2(RCC_APB2ENR_SYSCFGEN, FALSE); // Enable sys cfg controller SYSCFG->EXTICR[1] &= 0xFFFFFFF0; // EXTI4 is connected to PortA // Configure EXTI line EXTI->IMR |= GPIO0_IRQ_MASK; // Interrupt mode enabled EXTI->EMR &= ~GPIO0_IRQ_MASK; // Event mode disabled EXTI->RTSR &= ~GPIO0_IRQ_MASK; // Rising trigger disabled EXTI->FTSR |= GPIO0_IRQ_MASK; // Falling trigger enabled EXTI->PR = GPIO0_IRQ_MASK; // Clean irq flag nvicEnableVector(EXTI4_IRQn, CORTEX_PRIORITY_MASK(STM32_EXT_EXTI4_IRQ_PRIORITY)); }
void PillReset() { PillDeinit(); PinSetupOut(PERIPH_PWR_GPIO, PERIPH_PWR_PIN, omPushPull); // Power PinSet(PERIPH_PWR_GPIO, PERIPH_PWR_PIN); chThdSleepMilliseconds(1); // Allow power to rise i2c.Resume(); }
uint8_t cc1101_t::Init() { // ==== GPIO ==== PinSetupOut (CC_GPIO, CC_CS, omPushPull); PinSetupAlterFunc(CC_GPIO, CC_SCK, omPushPull, pudNone, CC_SPI_AF); PinSetupAlterFunc(CC_GPIO, CC_MISO, omPushPull, pudNone, CC_SPI_AF); PinSetupAlterFunc(CC_GPIO, CC_MOSI, omPushPull, pudNone, CC_SPI_AF); IGdo0.Init(ttFalling); //PinSetupAnalog (CC_GPIO, CC_GDO2); // GDO2 not used CsHi(); // ==== SPI ==== // MSB first, master, ClkLowIdle, FirstEdge, Baudrate no more than 6.5MHz ISpi.Setup(boMSB, cpolIdleLow, cphaFirstEdge, sbFdiv16); ISpi.Enable(); // ==== Init CC ==== if(Reset() != OK) { ISpi.Disable(); Uart.Printf("\rCC Rst Fail"); return FAILURE; } // Check if success WriteRegister(CC_PKTLEN, 7); uint8_t Rpl = ReadRegister(CC_PKTLEN); if(Rpl != 7) { ISpi.Disable(); Uart.Printf("\rCC R/W Fail; rpl=%u", Rpl); return FAILURE; } // Proceed with init FlushRxFIFO(); RfConfig(); IGdo0.EnableIrq(IRQ_PRIO_HIGH); return OK; }
void sd_t::Init() { IsReady = FALSE; // Bus pins PinSetupAlterFunc(GPIOC, 8, omPushPull, pudPullUp, AF12, ps50MHz); PinSetupAlterFunc(GPIOC, 9, omPushPull, pudPullUp, AF12, ps50MHz); PinSetupAlterFunc(GPIOC, 10, omPushPull, pudPullUp, AF12, ps50MHz); PinSetupAlterFunc(GPIOC, 11, omPushPull, pudPullUp, AF12, ps50MHz); PinSetupAlterFunc(GPIOC, 12, omPushPull, pudNone, AF12, ps50MHz); PinSetupAlterFunc(GPIOD, 2, omPushPull, pudPullUp, AF12, ps50MHz); // Power pin PinSetupOut(GPIOC, 4, omPushPull, pudNone); PinClear(GPIOC, 4); // Power on Delay_ms(450); FRESULT err; sdcInit(); sdcStart(&SDCD1, NULL); if (sdcConnect(&SDCD1)) { Uart.Printf("SD connect error\r"); return; } else { Uart.Printf("SD capacity: %u\r", SDCD1.capacity); } err = f_mount(0, &SDC_FS); if (err != FR_OK) { Uart.Printf("SD mount error\r"); sdcDisconnect(&SDCD1); return; } IsReady = TRUE; }
void Infrared_t::RxInit() { chEvtInit(&IEvtSrcIrRx); // GPIO PinSetupOut(IR_RX_PWR_GPIO, IR_RX_PWR_PIN, omPushPull); // } PinSet(IR_RX_PWR_GPIO, IR_RX_PWR_PIN); // } Power PinSetupIn(IR_RX_IN_GPIO, IR_RX_IN_PIN, pudNone); // Input // ==== Timer ==== RxTimer.Init(); RxTimer.Enable(); RxTimer.SetTopValue(0xFFFF); // Maximum RxTimer.SetupPrescaler(1000000); // Input Freq: 1 MHz => one tick = 1 uS //RxTimer.Disable(); // ==== Input queue ==== chMBInit(&imailbox, IRxBuf, IR_RXBUF_SZ); // ==== Receiving thread ==== chThdCreateStatic(waIRRxThread, sizeof(waIRRxThread), NORMALPRIO, IRRxThread, NULL); // ==== IRQ ==== PC5 rccEnableAPB2(RCC_APB2ENR_SYSCFGEN, FALSE); // Enable sys cfg controller SYSCFG->EXTICR[1] &= 0xFFFFFF0F; // EXTI5 is connected to PortC SYSCFG->EXTICR[1] |= 0x00000020; // EXTI5 is connected to PortC // Configure EXTI line EXTI->IMR |= IR_IRQ_MASK; // Interrupt mode enabled EXTI->EMR &= ~IR_IRQ_MASK; // Event mode disabled RxIrqWaitFalling(); EXTI->PR = IR_IRQ_MASK; // Clean irq flag nvicEnableVector(EXTI9_5_IRQn, CORTEX_PRIORITY_MASK(IRQ_PRIO_HIGH)); }
void Init() { JtagDisable(); Uart.Init(USART2, 256000); #ifndef TESTING // Charging and powering PinSetupIn(EXT_PWR_GPIO, EXT_PWR_PIN, pudPullDown); PinSetupIn(CHARGING_GPIO, CHARGING_PIN, pudPullUp); LedsInit(); VibroInit(); if(!Iwdg.ResetOccured()) { Uart.Printf("Glove1_f100 AHB=%u; APB1=%u; APB2=%u\r", Clk.AHBFreqHz, Clk.APB1FreqHz, Clk.APB2FreqHz); Vibro.On(100); chThdSleepMilliseconds(99); ShowChargeLevel(); chThdSleepMilliseconds(900); SwitchOffEverything(); } else Uart.Printf("W\r"); AccInit(); // Application init App.Init(); #else Uart.Printf("Glove tester\r"); PinSetupOut(GPIOA, 15, omPushPull); PinSet(GPIOA, 15); chThdSleepMilliseconds(450); Acc[0].SetPortAndPins(GPIOA, 1, 3, 4); #endif }
void Sound_t::Init() { // ==== GPIO init ==== PinSetupOut(VS_GPIO, VS_RST, omPushPull); PinSetupOut(VS_GPIO, VS_XCS, omPushPull); PinSetupOut(VS_GPIO, VS_XDCS, omPushPull); Rst_Lo(); XCS_Hi(); XDCS_Hi(); chThdSleepMilliseconds(45); PinSetupIn(VS_GPIO, VS_DREQ, pudPullDown); PinSetupAlterFunc(VS_GPIO, VS_XCLK, omPushPull, pudNone, VS_AF); PinSetupAlterFunc(VS_GPIO, VS_SO, omPushPull, pudNone, VS_AF); PinSetupAlterFunc(VS_GPIO, VS_SI, omPushPull, pudNone, VS_AF); // ==== SPI init ==== ISpi.Setup(VS_SPI, boMSB, cpolIdleLow, cphaFirstEdge, sbFdiv8); ISpi.Enable(); ISpi.EnableTxDma(); // ==== DMA ==== // Here only unchanged parameters of the DMA are configured. dmaStreamAllocate (VS_DMA, IRQ_PRIO_MEDIUM, SIrqDmaHandler, NULL); dmaStreamSetPeripheral(VS_DMA, &VS_SPI->DR); dmaStreamSetMode (VS_DMA, VS_DMA_MODE); // ==== Variables ==== State = sndStopped; IDmaIdle = true; PBuf = &Buf1; IAttenuation = VS_INITIAL_ATTENUATION; chMBInit(&CmdBox, CmdBuf, VS_CMD_BUF_SZ); // ==== Init VS ==== Rst_Hi(); chThdSleepMilliseconds(7); Clk.MCO1Enable(mco1HSE, mcoDiv1); // Only after reset, as pins are grounded when Rst is Lo chThdSleepMilliseconds(7); // ==== DREQ IRQ ==== IDreq.Setup(VS_GPIO, VS_DREQ, ttRising); // ==== Thread ==== PThread = chThdCreateStatic(waSoundThread, sizeof(waSoundThread), NORMALPRIO, (tfunc_t)SoundThread, NULL); #if VS_AMPF_EXISTS PinSetupOut(VS_AMPF_GPIO, VS_AMPF_PIN, omPushPull); AmpfOff(); #endif }
void radio_t::Init(uint16_t ASelfID) { #ifdef DBG_PINS PinSetupOut(DBG_GPIO1, DBG_PIN1, omPushPull); #endif // Init radioIC CC.Init(); CC.SetTxPower(CC_Pwr0dBm); CC.SetChannel(CHANNEL_ZERO); // Thread PThread = chThdCreateStatic(warradioThread, sizeof(warradioThread), HIGHPRIO, (tfunc_t)radioThread, NULL); }
void Init() { JtagDisable(); Uart.Init(57600); Pwr.Init(); // Get ID uint8_t id = GetID(); rLevel1.Init(id, Pwr0dBm); // LED PinSetupOut(GPIOB, 0, omPushPull); Uart.Printf("\rTx2 id=%u Pwr=-27 dBm\r", id); //Uart.Printf("AHB=%u; APB1=%u; APB2=%u\r", Clk.AHBFreqHz, Clk.APB1FreqHz, Clk.APB2FreqHz); }
void PillInit() { PillDeinit(); PinSetupOut(PERIPH_PWR_GPIO, PERIPH_PWR_PIN, omPushPull); // Power PinSet(PERIPH_PWR_GPIO, PERIPH_PWR_PIN); chThdSleepMilliseconds(1); // Allow power to rise i2c.Init(PILL_I2C, PILL_I2C_GPIO, PILL_SCL_PIN, PILL_SDA_PIN, PILL_I2C_BITRATE_HZ, PILL_DMATX, PILL_DMARX); // Firmware chEvtInit(&IEvtPillChange); // Pills for(uint8_t i=0; i<PILL_CNT; i++) Pill[i].Init(i); // Thread chThdCreateStatic(waPillThread, sizeof(waPillThread), NORMALPRIO, PillThread, NULL); }
int main(void) { // ==== Init Vcore & clock system ==== SetupVCore(vcore1V5); Clk.SetupFlashLatency(16); uint8_t ClkRslt = Clk.SwitchToHSI(); if(ClkRslt == OK) Clk.DisableMSI(); Clk.UpdateFreqValues(); // ==== Init OS ==== halInit(); chSysInit(); // ==== Init Hard & Soft ==== Uart.Init(115200); Uart.Printf("\rBmstuCtrl AHB=%u", Clk.AHBFreqHz); if(ClkRslt != OK) Uart.Printf("\rClk switch failure"); // Path init PinSetupOut(PATH_GPIO, PATH21_PIN, omPushPull); PinSetupOut(PATH_GPIO, PATH31_PIN, omPushPull); PinSetupOut(PATH_GPIO, PATH22_PIN, omPushPull); PinSetupOut(PATH_GPIO, PATH32_PIN, omPushPull); // Led init PinSetupOut(LED_GPIO, LED_PIN, omPushPull); // App.Init(); App.PThread = chThdSelf(); // Timers chSysLock(); chVTSetI(&App.TmrUartRx, MS2ST(UART_RX_POLLING_MS), TmrUartRxCallback, nullptr); chSysUnlock(); // Main cycle while(true) App.ITask(); }
void eAdc_t::Init() { PThread = chThdSelf(); PinSetupOut(ADC_GPIO, ADC_CNV, omPushPull, pudNone); PinSetupOut(ADC_GPIO, ADC_SDI, omPushPull, pudNone); PinSetupAlterFunc(ADC_GPIO, ADC_SCLK, omPushPull, pudNone, AF5); PinSetupAlterFunc(ADC_GPIO, ADC_SDO, omPushPull, pudNone, AF5); PinSet(ADC_GPIO, ADC_SDI); //select CS MODE ADC_CNV_LOW(); // Idle mode // ==== DMA ==== dmaStreamAllocate (EADC_DMA, IRQ_PRIO_MEDIUM, SIrqDmaHandler, NULL); dmaStreamSetPeripheral(EADC_DMA, &ADC_SPI->DR); dmaStreamSetMode (EADC_DMA, EADC_DMA_MODE); dmaStreamSetMemory0(EADC_DMA, &Adc.Rslt); dmaStreamSetTransactionSize(EADC_DMA, 1); dmaStreamEnable(EADC_DMA); // ==== SPI ==== MSB first, master, ClkLowIdle, FirstEdge, Baudrate=... // Select baudrate (2.4MHz max): APB=120MHz => div = 64 ISpi.Setup(ADC_SPI, boMSB, cpolIdleLow, cphaFirstEdge, sbFdiv64, sbc16Bit); ISpi.SetModeRxOnly(); ISpi.EnableRxDma(); ISpi.Enable(); // ==== Sampling timer ==== SamplingTmr.Init(TIM2); SamplingTmr.SetUpdateFrequency(FSAMPL_ADC); SamplingTmr.EnableIrq(TIM2_IRQn, IRQ_PRIO_MEDIUM); SamplingTmr.EnableIrqOnUpdate(); SamplingTmr.Enable(); CskTmr.Init(TIM5); CskTmr.SetUpdateFrequency(FSAMPL_CNV); // request 2 usec CskTmr.EnableIrq(TIM5_IRQn, IRQ_PRIO_MEDIUM); CskTmr.EnableIrqOnUpdate(); CskTmr.Disable(); }
void Adc_t::Init() { PinSetupOut(ADC_GPIO, ADC_CSIN_PIN, omPushPull, pudNone); PinSetupAlterFunc(ADC_GPIO, ADC_SCK_PIN, omPushPull, pudNone, ADC_SPI_AF); PinSetupAlterFunc(ADC_GPIO, ADC_DOUT_PIN, omPushPull, pudNone, ADC_SPI_AF); CsHi(); // ==== SPI ==== MSB first, master, ClkLowIdle, FirstEdge, Baudrate=... // Select baudrate (2.4MHz max): APB=32MHz => div = 16 ISpi.Setup(SPI_ADC, boMSB, cpolIdleLow, cphaFirstEdge, sbFdiv16); ISpi.SetRxOnly(); ISpi.EnableRxDma(); // ==== DMA ==== dmaStreamAllocate (DMA_ADC, IRQ_PRIO_MEDIUM, SIrqDmaHandler, NULL); dmaStreamSetPeripheral(DMA_ADC, &SPI_ADC->DR); dmaStreamSetMode (DMA_ADC, ADC_DMA_MODE); }
int main(void) { // ==== Setup clock frequency ==== uint8_t ClkResult = 1; Clk.SetupFlashLatency(64); // Setup Flash Latency for clock in MHz Clk.EnablePrefetch(); // 12 MHz/6 = 2; 2*192 = 384; 384/6 = 64 (preAHB divider); 384/8 = 48 (USB clock) Clk.SetupPLLDividers(6, 192, pllSysDiv6, 8); // 64/1 = 64 MHz core clock. APB1 & APB2 clock derive on AHB clock; APB1max = 42MHz, APB2max = 84MHz // Keep APB freq at 32 MHz to left peripheral settings untouched Clk.SetupBusDividers(ahbDiv1, apbDiv2, apbDiv2); if((ClkResult = Clk.SwitchToPLL()) == 0) Clk.HSIDisable(); Clk.UpdateFreqValues(); // Init OS halInit(); chSysInit(); // ==== Init hardware ==== Uart.Init(115200, UART_GPIO, UART_TX_PIN, UART_GPIO, UART_RX_PIN); Uart.Printf("\r%S %S", APP_NAME, APP_VERSION); Clk.PrintFreqs(); if(ClkResult != 0) Uart.Printf("\rXTAL failure"); App.InitThread(); // Leds LedAux.Init(); for(uint8_t i=0; i<4; i++) { Led[i].Init(); // for(uint8_t j=0; j<250; j++) { // Led[i].Set(j); // chThdSleepMilliseconds(4); // } // Led[i].Set(0); } // Debug: init CS2 as output PinSetupOut(GPIOC, 13, omPushPull, pudNone); // ==== USB ==== UsbAu.Init(); UsbAu.Connect(); Pcm.Init(); // Main cycle App.ITask(); }
int main(void) { Init(); Uart.Printf("klNFC\r"); PinSetupOut(GPIOC, 8, poPushPull, pudNone); //PinSetupOut(GPIOC, 9, poPushPull, pudNone); PinSet(GPIOC, 8); uint32_t Tmr; while(1) { if(Delay.Elapsed(&Tmr, 198)) { PinToggle(GPIOC, 8); Uart.Printf("ege\r"); //USART_SendData(USART1, 'e'); } //Delay.ms(999); //PinToggle(GPIOC, 8); } }
void AccInit() { // Init pwr PinSetupOut(GPIOA, 15, omPushPull); PinSet(GPIOA, 15); chThdSleepMilliseconds(450); // Set ports & pins Acc[0].SetPortAndPins(GPIOA, 1, 3, 4); Acc[1].SetPortAndPins(GPIOA, 5, 6, 7); Acc[2].SetPortAndPins(GPIOC, 0, 1, 2); Acc[3].SetPortAndPins(GPIOC, 3, 4, 5); Acc[4].SetPortAndPins(GPIOC, 6, 7, 8); Acc[5].SetPortAndPins(GPIOC, 10, 11, 12); Acc[6].SetPortAndPins(GPIOB, 13, 14, 15); // Init for(uint8_t i=0; i<ACC_CNT; i++) { Acc[i].Init(); if(!Acc[i].IsOperational) Uart.Printf("Acc %u is not operational\r", i); } }
int main(void) { // ==== Init Vcore & clock system ==== SetupVCore(vcore1V8); Clk.UpdateFreqValues(); // ==== Init OS ==== halInit(); chSysInit(); // ==== Init Hard & Soft ==== PinSetupOut(GPIOC, 9, omPushPull); PinSet(GPIOC, 9); while(1) { // PinSet(GPIOC, 8); // chThdSleepMilliseconds(207); // PinClear(GPIOC, 8); // chThdSleepMilliseconds(360); } // while }
void cc1101_t::Init() { // ==== GPIO ==== PinSetupOut (CC_GPIO, CC_CS, omPushPull, pudNone); PinSetupAlterFunc(CC_GPIO, CC_SCK, omPushPull, pudNone, AF5); PinSetupAlterFunc(CC_GPIO, CC_MISO, omPushPull, pudNone, AF5); PinSetupAlterFunc(CC_GPIO, CC_MOSI, omPushPull, pudNone, AF5); PinSetupIn (CC_GPIO, CC_GDO0, pudNone); PinSetupIn (CC_GPIO, CC_GDO2, pudNone); CsHi(); // ==== SPI ==== MSB first, master, ClkLowIdle, FirstEdge, Baudrate=f/2 ISpi.Setup(CC_SPI, boMSB, cpolIdleLow, cphaFirstEdge, sbFdiv2); ISpi.Enable(); // ==== Init CC ==== CReset(); FlushRxFIFO(); RfConfig(); PWaitingThread = nullptr; // ==== IRQ ==== IGdo0.Setup(CC_GPIO, CC_GDO0, ttFalling); IGdo0.EnableIrq(IRQ_PRIO_HIGH); }
void Stones_t::Init() { i2c.Init(); // i2c.BusScan(); // Stones init for(uint32_t i=0; i<16; i++) { Stone[0][i].BrtCurrent = 0; Stone[0][i].BrtDesired = 0; Stone[1][i].BrtCurrent = 0; Stone[1][i].BrtDesired = 0; } // Enable LEDs PinSetupOut(GPIOB, 8, omPushPull); PinClear(GPIOB, 8); // Always enabled // Init PCAs uint8_t rslt; rslt = i2c.Write(PcaAddr[0], (uint8_t*)PcaInitPkt, PCAINITPKT_SZ); if(rslt != OK) Uart.Printf("\rPCA0 Init Failure %u", rslt); rslt = i2c.Write(PcaAddr[1], (uint8_t*)PcaInitPkt, PCAINITPKT_SZ); if(rslt != OK) Uart.Printf("\rPCA1 Init Failure %u", rslt); // Create and start thread chThdCreateStatic(waStonesThread, sizeof(waStonesThread), NORMALPRIO, (tfunc_t)StonesThread, NULL); }
void cc1101_t::Init() { // ==== GPIO ==== PinSetupOut(GPIOA, CC_CS, omPushPull); PinSetupAlterFuncOutput(GPIOA, CC_SCK, omPushPull); PinSetupAlterFuncOutput(GPIOA, CC_MISO, omPushPull); PinSetupAlterFuncOutput(GPIOA, CC_MOSI, omPushPull); PinSetupIn(GPIOA, CC_GDO0, pudNone); PinSetupIn(GPIOA, CC_GDO2, pudNone); CsHi(); // ==== SPI ==== MSB first, master, ClkLowIdle, FirstEdge, Baudrate=f/2 SpiSetup(CC_SPI, boMSB, cpolIdleLow, cphaFirstEdge, sbFdiv2); SpiEnable(CC_SPI); // ==== Init CC ==== CReset(); FlushRxFIFO(); RfConfig(); chEvtInit(&IEvtSrcRx); chEvtInit(&IEvtSrcTx); State = ccIdle; // ==== IRQ ==== RCC->APB2ENR |= RCC_APB2ENR_AFIOEN; // Enable AFIO clock uint8_t tmp = CC_GDO0 / 4; // Indx of EXTICR register uint8_t Shift = (CC_GDO0 & 0x03) * 4; AFIO->EXTICR[tmp] &= ~((uint32_t)0b1111 << Shift); // Clear bits and leave clear to select GPIOA tmp = 1<<CC_GDO0; // IRQ mask // Configure EXTI line EXTI->IMR |= tmp; // Interrupt mode enabled EXTI->EMR &= ~tmp; // Event mode disabled EXTI->RTSR &= ~tmp; // Rising trigger disabled EXTI->FTSR |= tmp; // Falling trigger enabled EXTI->PR = tmp; // Clean irq flag nvicEnableVector(EXTI4_IRQn, CORTEX_PRIORITY_MASK(IRQ_PRIO_MEDIUM)); }
void Lcd_t::Init(void) { BckLt.Init(); // ==== GPIOs ==== // Configure LCD_XRES, LCD_XCS, LCD_SCLK & LCD_SDA as Push-Pull output PinSetupOut(LCD_GPIO, LCD_XRES, omPushPull); PinSetupOut(LCD_GPIO, LCD_XCS, omPushPull); PinSetupOut(LCD_GPIO, LCD_SCLK, omPushPull); PinSetupOut(LCD_GPIO, LCD_SDA, omPushPull); // ========================= Init LCD ====================================== SCLK_Lo(); XCS_Hi(); // Reset display XRES_Lo(); chThdSleepMilliseconds(7); XRES_Hi(); IWriteCmd(0xAF); // display ON // Reset display again XRES_Lo(); chThdSleepMilliseconds(7); XRES_Hi(); chThdSleepMilliseconds(7); // Initial commands IWriteCmd(0xAF); // display ON IWriteCmd(0xA4); // Set normal display mode IWriteCmd(0x2F); // Charge pump on IWriteCmd(0x40); // Set start row address = 0 #if LCD_MIRROR_Y_AXIS IWriteCmd(0xC8); // Mirror Y axis #endif #if LCD_MIRROR_X_AXIS IWriteCmd(0xA1); // Mirror X axis #endif // Set x=0, y=0 IWriteCmd(0xB0); // Y axis initialization IWriteCmd(0x10); // X axis initialisation1 IWriteCmd(0x00); // X axis initialisation2 Cls(); #if LCD_DMA_BASED // ================ Switch to USART + DMA ==================== PinSetupAlterFunc(LCD_GPIO, LCD_SCLK, omPushPull, pudNone, AF7, ps40MHz); PinSetupAlterFunc(LCD_GPIO, LCD_SDA, omPushPull, pudNone, AF7, ps40MHz); // ==== USART init ==== clock enabled, idle low, first edge, enable last bit pulse rccEnableUSART3(FALSE); USART3->CR1 = USART_CR1_UE; // Enable USART3->BRR = Clk.APB1FreqHz / LCD_UART_SPEED; USART3->CR2 = USART_CR2_CLKEN | USART_CR2_LBCL; // Enable clock, enable last bit clock USART3->CR1 = USART_CR1_UE | USART_CR1_M | USART_CR1_TE; USART3->CR3 = USART_CR3_DMAT; // Enable DMA at transmitter // DMA dmaStreamAllocate (LCD_DMA, IRQ_PRIO_LOW, nullptr, NULL); dmaStreamSetPeripheral(LCD_DMA, &USART3->DR); dmaStreamSetMemory0 (LCD_DMA, IBuf); dmaStreamSetTransactionSize(LCD_DMA, LCD_VIDEOBUF_SIZE); dmaStreamSetMode (LCD_DMA, LCD_DMA_TX_MODE); // Start transmission XCS_Lo(); dmaStreamEnable(LCD_DMA); #else #endif chSemInit(&semLcd, 1); }