static void switch_off(void) { // stop TIMER2 TMR2ON = 0; TMR2 = 0; // all LEDs off led_group(LED_ALL, false); // enable sleep mode IDLEN = 0; do { // go to sleep till wakeup IRQ INT1IE = 1; Sleep(); // filter out glitches __delay_ms(20); } while (!WAKEUP_BUTTON); // disable sleep mode IDLEN = 1; // initialize button state btn_init(); // reenable TIMER2 TMR2ON = 1; // reset idle timer idle_timer = 0; }
/**@brief Function for application main entry. */ int main(void) { uint32_t err_code; bool erase_bonds; // Initialize. app_trace_init(); timers_init(); buttons_leds_init(&erase_bonds); ble_stack_init(); device_manager_init(erase_bonds); gap_params_init(); advertising_init(); services_init(); sensor_simulator_init(); conn_params_init(); #if defined(__RING_SUPPORT__) btn_init(); spi_flash_init(); sensor_init(); lcd_init(); #endif // Start execution. application_timers_start(); err_code = ble_advertising_start(BLE_ADV_MODE_FAST); APP_ERROR_CHECK(err_code); // Enter main loop. for (;;) { power_manage(); } }
/******************************************************************************* * function : hw_init ******************************************************************************/ void hw_init(void) { #if CONFIG_SYSCLOCK == CONFIG_SYSCLOCK_16MHZ hw_initSysclock(); #endif systick_init(CONFIG_SYSTICK_1MS); RCC->APB2ENR |= RCC_APB2ENR_SYSCFGEN; led_init(); btn_init(); }
/*! * \brief * buttons ioctl function * * \param cmd specifies the command to FLASH * \arg CTRL_DEINIT * \arg CTRL_INIT * \arg CTRL_GET_STATUS * \arg CTRL_FLUSH * \param buf pointer to buffer for ioctl * \return The status of the operation * \arg DRV_READY * \arg DRV_ERROR */ drv_status_en btn_ioctl (ioctl_cmd_t cmd, ioctl_buf_t buf) { switch (cmd) { case CTRL_DEINIT: /*!< De-init */ btn_deinit(); return DRV_READY; case CTRL_INIT: /*!< Init */ if (buf) *(drv_status_en*)buf = btn_init(); else btn_init(); return DRV_READY; case CTRL_GET_STATUS: /*!< Probe function */ if (buf) *(drv_status_en*)buf = BTN.status; return BTN.status = DRV_READY; case CTRL_FLUSH: btn_flush (); return BTN.status = DRV_READY; default: /*!< Unsupported command, error */ return DRV_ERROR; } }
/** * Initialize the templ theme * @param hue [0..360] hue value from HSV color space to define the theme's base color * @param font pointer to a font (NULL to use the default) * @return pointer to the initialized theme */ lv_theme_t * lv_theme_templ_init(uint16_t hue, lv_font_t *font) { if(font == NULL) font = LV_FONT_DEFAULT; _hue = hue; _font = font; /*For backward compatibility initialize all theme elements with a default style */ uint16_t i; lv_style_t **style_p = (lv_style_t**) &theme; for(i = 0; i < sizeof(lv_theme_t) / sizeof(lv_style_t*); i++) { *style_p = &def; style_p++; } basic_init(); cont_init(); btn_init(); label_init(); img_init(); line_init(); led_init(); bar_init(); slider_init(); sw_init(); lmeter_init(); gauge_init(); chart_init(); cb_init(); btnm_init(); kb_init(); mbox_init(); page_init(); ta_init(); list_init(); ddlist_init(); roller_init(); tabview_init(); win_init(); return &theme; }
void connect_to_peripherals() { // bt_init(); // Flash button LEDs btn_init(); // if (bt_is_connected) { // BLUE_LED = 1; // WHITE_LED = 1; // delay_n_ms(2); // WHITE_LED = 0; // delay_n_ms(2); // WHITE_LED = 1; // delay_n_ms(2); // WHITE_LED = 0; // delay_n_ms(2); // WHITE_LED = 1; // delay_n_ms(2); // BLUE_LED = 0; // WHITE_LED = 0; // } else { // BLUE_LED = 1; // RED_LED = 1; // delay_n_ms(2); // RED_LED = 0; // delay_n_ms(2); // delay_n_ms(2); // RED_LED = 0; // delay_n_ms(2); // RED_LED = 1; // delay_n_ms(2); // BLUE_LED = 0; // RED_LED = 0; // } reset_to_start(); }
int main(void) { WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer BCSCTL1 = CALBC1_8MHZ; // Set DCO to 8Mhz DCOCTL = CALDCO_8MHZ; // Set DCO to 8Mhz P1DIR = BIT0; // P1.0 and P1.6 are the red+green LEDs P1OUT = BIT0; btn_init(); uart_init(); uart_send('>'); // uart_set_tx_isr_ptr(uart_tx_isr); __bis_SR_register(GIE); while(1){ uart_send(btn_sequence()); P1OUT ^= BIT0; } return 0; }
int main(int argc, char ** argv) { struct acc_info acc; uint32_t cnt = 0; int dt; int x; int y; int i; /* calibrate usecond delay loop */ cm3_udelay_calibrate(); __leds_io_init(); __leds_all_on(); udelay(100000); __leds_all_off(); udelay(100000); /* Initialize the stdin, stdout and stderr */ stdio_init(); __leds_all_on(); udelay(100000); /* Print a useful information message */ printf("\n"); __leds_all_off(); printf("---------------------------------------------------------\n"); printf(" STM32F4 Discovery example\n"); printf("---------------------------------------------------------\n"); printf("\n"); // while (1) { // __leds_all_on(); // udelay(100000); // __leds_all_off(); // udelay(100000); // } thinkos_init(THINKOS_OPT_PRIORITY(4) | THINKOS_OPT_ID(4)); leds_init(); btn_init(); #if 0 for (i = 0; ; ++i) { led_off((i - 2) & 0x7); led_on(i & 0x7); dt = i & 255; if (dt > 127) dt = 255 - dt; thinkos_sleep(dt); } #endif acc.sem = thinkos_sem_alloc(0); printf("%s(): acc.sem=%d.\n", __func__, acc.sem); thinkos_thread_create((void *)accelerometer_task, (void *)&acc, accelerometer_stack, sizeof(accelerometer_stack) | THINKOS_OPT_PRIORITY(1)); for (i = 0; ; ++i) { thinkos_sem_wait(acc.sem); if (btn_event_get() == BTN_PRESSED) { /* request calibration */ acc.cal_req = true; } /* Scale */ x = acc.x * 64 / 512; y = acc.y * 64 / 512; if ((++cnt & 0x03) == 0) { printf("%5d,%5d\r", x, y); } if (x == 0) { led_on(1); led_on(3); } else if (x < 0) { led_blink(3, -x); led_off(1); } else { led_blink(1, x); led_off(3); } if (y == 0) { led_on(0); led_on(2); } else if (y < 0) { led_off(0); led_blink(2, -y); } else { led_off(2); led_blink(0, y); } } return 0; }
void myinit(void) { #pragma message "myinit()" #pragma message "HAL_Init()" #pragma message "SystemClock_Config()" HAL_Init(); SystemClock_Config(); #ifdef ENABLE_GPIO #pragma message "led_init()" led_init(); #ifdef btn_init #pragma message "btn_init()" btn_init(); #endif #endif #ifdef ENABLE_RNG #pragma message "rng_init()" rng_init(); #endif #ifdef ENABLE_UART #pragma message "uart_init()" uart_init(); #endif #ifdef ENABLE_I2C #pragma message "i2c_init()" i2c_init(); #endif #ifdef ENABLE_SPI #pragma message "spi_init()" spi_init(); #endif #ifdef ENABLE_TIM #pragma message "tim_init()" tim_init(); #endif #ifdef ENABLE_ADC #pragma message "adc_init()" adc_init(); #endif #ifdef ENABLE_CAN #pragma message "can_init()" can_init(); #endif #ifdef ENABLE_DAC #pragma message "dac_init()" dac_init(); #endif #ifdef ENABLE_DMA #pragma message "dma_init()" dma_init(); #endif #ifdef ENABLE_FLASH #pragma message "flash_erase_img1()" flash_erase_img1(); #endif #ifdef ENABLE_ETH #pragma message "eth_init()" eth_init(); #endif #ifdef ENABLE_DSP #pragma message "dsp_init()" dsp_init(); #endif #ifdef ENABLE_USB #pragma message "usb_init()" usb_init(); #endif #ifdef ENABLE_PCL #pragma message "pcl_init()" pcl_init(); #endif #ifdef ENABLE_SDIO #pragma message "sdio_init()" sdio_init(); #endif #ifdef ENABLE_DISPLAY #pragma message "display_init()" display_init(); #endif #ifdef ENABLE_BR #pragma message "br_init()" br_init(); #endif }
/* Main function * * - Initialise device and any global variables * - Enable Interrupts * - Start endless loop */ void main(void) { unsigned long ulRetcode; // Initialise the device clock to 80MHz ROM_SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN ); // Enable SysTick for FatFS at 10ms intervals ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / 100); ROM_SysTickEnable(); ROM_SysTickIntEnable(); // // Configure and enable uDMA // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA); SysCtlDelay(10); ROM_uDMAControlBaseSet(&sDMAControlTable[0]); ROM_uDMAEnable(); // // Enable the USB controller. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_USB0); // // Set the USB pins to be controlled by the USB controller. ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); ROM_GPIOPinTypeUSBAnalog(GPIO_PORTD_BASE, GPIO_PIN_4 | GPIO_PIN_5); // Initialize the idle timeout and reset all flags. // g_ulIdleTimeout = 0; g_ulFlags = 0; // // Initialize the state to idle. // g_eMSCState = MSC_DEV_DISCONNECTED; // // Set the USB stack mode to Device mode with VBUS monitoring. // USBStackModeSet(0, USB_MODE_DEVICE, 0); // // Pass our device information to the USB library and place the device // on the bus. // USBDMSCInit(0, (tUSBDMSCDevice *)&g_sMSCDevice); // // Determine whether or not an SDCard is installed. If not, print a // warning and have the user install one and restart. // ulRetcode = disk_initialize(0); // Enable Global interrupts ROM_IntMasterEnable(); // Enable floating point arithmetic unit, but disable stacking ROM_FPUEnable(); ROM_FPUStackingDisable(); // Initialise GPIO - All ports enabled ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); // Unlock NMI pins for GPIO usage (PD7 + PF0) HWREG(GPIO_PORTD_BASE + 0x520) = 0x4C4F434B; HWREG(GPIO_PORTF_BASE + 0x520) = 0x4C4F434B; HWREG(GPIO_PORTD_BASE + 0x524) = 0x000000FF; HWREG(GPIO_PORTF_BASE + 0x524) = 0x000000FF; HWREG(GPIO_PORTD_BASE + 0x520) = 0x00000000; HWREG(GPIO_PORTF_BASE + 0x520) = 0x00000000; // Initialise GPIO Expander (probably not happening) // Initialise Buttons btn_init(); // Initialise FX fx_init(); // Initialise ADC adc_init(); // Initialise DAC dac_init(); // Initialise SD Card and Mass storage sdcard_init(); // Initialise UART for debugging uart_init(); // Initialise Timers timers_init(); for(;;) { // Endless Loop ADCProcessorTrigger(ADC0_BASE, 0); SysCtlDelay(SysCtlClockGet() / 120); // 25ms } }
// Start Of Program - this is where we setup everything before getting into the main loop void main(void) { // Oscillator setup OSCCON = 0b11100000; // device enters idle on Sleep(), 8Mhz Clock, OSCTUNE = 0b00000000; // Internal oscillator low freq comes from 31Khz clock from LFINTOSC, PLL disabled // Analog / Digital pins setup ANSEL = 0b00000000; // disable all analog inputs (make them all digital) must do this! ANSELH = 0b00000000; // disable all analog inputs (make them all digital) must do this! // Tristate setup TRISA = 0b00000011; TRISB = 0b11111110; TRISC = 0b00000000; TRISD = 0b00000000; TRISE = 0b00000000; // configure TIMER2: // prescaler 16, period register for 1ms, timer stopped T2CON = 0b00000010; TMR2 = 0; PR2 = _XTAL_FREQ / 1000 / 16 / 4; // initialize subsystems btn_init(); init_all(); // disable INT1, config for raising endge INT1IE = 0; INTEDG1 = 1; // enable interrupts TMR2IE = 1; // TIMER2 interrupt PEIE = 1; // peripheral interrupt GIE = 1; // global interrupt enable // start TIMER2 TMR2ON = 1; // main loop while (true) { off_flag = false; // go to idle and wait for timer Sleep(); // read button inputs btn_update(); // check for commands check_select(); check_off(); check_idle(); // execute mode task switch (mode) { case modeSelect: mode_select(); break; case modeSparkle: sparkle_leds(); break; case modeShiftReg: shiftreg_task(); break; case modeLightTest: led_group(LED_ALL, true); break; case modePOV: povmsg_task(); break; case modeBinDice: case modeDecDice: dice_task(mode == modeDecDice); break; case modeGame: game_task(); break; case mode4BitLogic: logic_4bit_task(); break; default: logic_task(); flipflop_task(); counter_task(mode == modeGrayCnt); } if (off_flag) { switch_off(); } } }
int main() { u8 data[ 4 ]; int res; leds_init(); btn_init(); ind_init(); uart_init(); sei(); ledvm_init(); i2cee_init(); pgm_init(); //stdout = &mystdout; nrf_init(); nrf_set_own_addr( lights_addr ); nrf_set_mode( NRF_MODE_RX ); while( 1 ) { // Something to execute? if( pgm_crt != -1 ) { res = ledvm_run(); if( res != LEDVM_ERR_OK ) { if( res == LEDVM_ERR_FINISHED ) // program finished, look for the next one { if( pgm_cycle ) { res = pgm_get_next_index( pgm_crt, 1 ); if( res != -1 ) // if found use the other program, otherwise don't change it pgm_crt = res; } ledvm_init(); } else { ledvm_ll_setrgb( 0, 0, 0 ); pgm_crt = -1; } } } // New data via radio? if( nrf_get_packet( data, 4, NULL ) == 4 ) { // Got data, interpret it if( data[ 0 ] == CMD_START_WRITE ) { pgm_recv_on = 1; pgm_recv_slot = data[ 3 ]; pgm_recv_addr = 0; pgm_recv_buf_idx = 0; if( pgm_recv_slot == pgm_crt ) pgm_crt = -1; } else if( data[ 0 ] == CMD_END_WRITE ) { pgm_recv_on = 0; pgm_recv_to_flash(); pgm_set_program_state( pgm_recv_slot, 1 ); if( pgm_crt == -1 ) pgm_crt = pgm_get_first_index(); } else if( data[ 0 ] == CMD_RUN ) { if( pgm_mask & ( 1 << data[ 3 ] ) ) { pgm_crt = data[ 3 ]; ledvm_init(); } } else if( data[ 0 ] == CMD_RAW ) { pgm_crt = -1; ledvm_ll_setrgb( data[ 1 ], data[ 2 ], data[ 3 ] ); } else if( data[ 0 ] == CMD_DEL ) { pgm_set_program_state( data[ 3 ], 0 ); if( pgm_crt == data[ 3 ] ) { pgm_crt = pgm_get_first_index(); ledvm_init(); } } else if( pgm_recv_on ) // instruction { memcpy( pgm_recv_buffer + pgm_recv_buf_idx, data, 4 ); pgm_recv_buf_idx += 4; if( pgm_recv_buf_idx == PGM_EE_PAGE_SIZE ) pgm_recv_to_flash(); } } // Handle buttons if( pgm_crt != -1 ) { btn_handler(); if( btn_is_pressed( BTN_NEXT_PIN ) ) { res = pgm_get_next_index( pgm_crt, 1 ); if( res != -1 ) pgm_crt = res; ledvm_init(); } else if( btn_is_pressed( BTN_PREV_PIN ) ) { res = pgm_get_next_index( pgm_crt, -1 ); if( res != -1 ) pgm_crt = res; ledvm_init(); } else if( btn_is_pressed( BTN_REPEAT_PIN ) ) ind_set( 1 - pgm_cycle ); } } }