int test_exti(struct harness_t *harness_p) { int i; struct exti_driver_t exti; struct pin_driver_t pin; pin_init(&pin, &pin_d4_dev, PIN_OUTPUT); pin_write(&pin, 1); BTASSERT(exti_init(&exti, &exti_d3_dev, EXTI_TRIGGER_FALLING_EDGE, isr, NULL) == 0); BTASSERT(exti_start(&exti) == 0); for (i = 0; i < 10; i++) { pin_write(&pin, 0); time_busy_wait_us(10000); pin_write(&pin, 1); time_busy_wait_us(10000); } std_printf(FSTR("flag = %d\r\n"), (int)flag); BTASSERT(flag == 10); return (0); }
void init(void) { pin_init(); timer_init(); LCD_init(); // eventually should read and save to eeprom. Keypad_init_static(); }
/* This function is meant to contain board-specific initialization code * for, e.g., the I/O pins. The initialization can rely on application- * specific board configuration, found in conf_board.h. */ void v2x_board_init(void) { irq_initialize_vectors(); pmic_init(); sysclk_init(); //configure clock sources for core and USB sleepmgr_init(); // Initialize the sleep manager ioport_init(); //Initializes the IOPORT service pin_init(); //whole chip pin init, modes and initial conditions spi_start(); //start SPI driver PWR_init(); //sets SR to default states - holds power up cpu_irq_enable(); eeprom_init(); //verifies eeprom safe for use menu_init(); //loads menu settings time_init(); //starts the RTC button_init(); //init button stuffs ACL_init(); //configures, but does not start sampling GSM_usart_init(); //starts direct serial channel to the SIM module CAN_uart_start(); //starts direct serial channel to the ELM module canbus_serial_routing(AVR_ROUTING); //cause the serial 3-state buffer to route the serial path from the ELM to the FTDI udc_start(); //start stack and vbus monitoring PWR_hub_start(); //connect the hub to the computer //autostart all systems delay_ms(500); GSM_modem_init(); CAN_elm_init(); ACL_set_sample_on(); PWR_host_start(); }
int main(void) { //uint8_t last_is_zero = 1; uint8_t i, is_active; uint8_t adcv, adcmax, adcmin; uint8_t score = 0, score_shifter = 0; pin_init(); adc_init(); while(1) { for (i=0, adcmax=0, adcmin=255; i<100; i++) { adc_start(); while (!(ADCSRA & (1<<ADIF))); adcv = ADCL; if (adcv > adcmax) adcmax = adcv; if (adcv < adcmin) adcmin = adcv; } rand_counter ++ ; tx_word(adcmax - adcmin); _delay_ms(400); } }
err_t one_wire_init(one_wire_t* ow, uint8_t port_n, uint8_t pin_n) { err_t res = pin_init(&ow->pin, port_n, pin_n); if(res != E_NO_ERROR) return res; one_wire_frame_end(ow); return E_NO_ERROR; }
int test_init(struct harness_t *harness_p) { BTASSERT(pcint_module_init() == 0); BTASSERT(pcint_module_init() == 0); pin_init(&pin, &pin_a8_dev, PIN_OUTPUT); return (0); }
int main(void) { pin_init(); ms_delay(100); while(1){ sort(500); ms_delay(1000); // 1 seconde avec led rouge allumée } }
int main(void) { // Run from the PLL at 120 MHz. g_ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), configCPU_CLOCK_HZ); // Initialize the device pinout appropriately for this board. pin_init(); // // Initialize the UART and write status. // ConfigureUART(); // Make sure the main oscillator is enabled because this is required by // the PHY. The system must have a 25MHz crystal attached to the OSC // pins. The SYSCTL_MOSC_HIGHFREQ parameter is used when the crystal // frequency is 10MHz or higher. SysCtlMOSCConfigSet(SYSCTL_MOSC_HIGHFREQ); // Create the LED task. if (LEDTaskInit() != 0) { while (1) { } } // Create the lwIP tasks. if (lwIPTaskInit() != 0) { while (1) { } } // Create the hello world task. /*if (hello_world_init() != 0) { while (1) { } }*/ UARTprintf("FreeRTOS + Lwip\n"); // Start the scheduler. This should not return. vTaskStartScheduler(); // In case the scheduler returns for some reason, loop forever. while (1) { } }
int main(int argc, const char * argv[]) { ZWLog logger = zlog_create(stdout, Debug); // ZWLog logger = NULL; ZWay zway = NULL; #ifdef _WINDOWS ZWError r = zway_init(&zway, ZSTR("COM3"), NULL, NULL, NULL, NULL, logger); #endif #ifdef __MACH__ ZWError r = zway_init(&zway, ZSTR("/dev/cu.SLAB_USBtoUART"), NULL, NULL, NULL, NULL, logger); #endif #ifdef __linux__ // ZWError r = zway_init(&zway, ZSTR("/dev/ttyUSB0"), NULL, NULL, NULL, NULL, logger); ZWError r = zway_init(&zway, ZSTR("/dev/ttyAMA0"), NULL, NULL, NULL, NULL, logger); #endif if (r != NoError) { printf("\n initError \n"); zway_log_error(zway, Critical, "Failed to init ZWay", r); return -1; } printf("\ncallback\n"); zway_device_add_callback(zway, DeviceAdded | DeviceRemoved | InstanceAdded | InstanceRemoved | CommandAdded | CommandRemoved, print_D_I_CC_event, NULL); printf("\nstart\n"); r = zway_start(zway, print_zway_terminated, NULL); if (r != NoError) { printf("\nstartError\n"); zway_log_error(zway, Critical, "Failed to start ZWay", r); return -1; } r = zway_discover(zway); if (r != NoError) { zway_log_error(zway, Critical, "Failed to negotiate with Z-Wave stick", r); return -1; } pin_init(); printf("\ndowork\n"); // Application code int code = do_work(zway); //int code =0; r = zway_stop(zway); zway_terminate(&zway); return code; }
int main(void) { fuse_init(); pin_init(); serial_init(); while (1) { serial_println("Hello"); __delay_ms(10); } return 0; }
/** * Create a new Pin object associated with the id. If additional * arguments are given, they are used to initialise the pin. See * `init`. */ static mp_obj_t class_pin_make_new(const mp_obj_type_t *type_p, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args_p) { struct class_pin_t *self_p; mp_map_t kwargs; static const mp_arg_t allowed_args[] = { { MP_QSTR_device, MP_ARG_REQUIRED | MP_ARG_INT }, { MP_QSTR_mode, MP_ARG_REQUIRED | MP_ARG_INT } }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; int device; int mode; mp_arg_check_num(n_args, n_kw, 1, MP_OBJ_FUN_ARGS_MAX, true); /* Parse args. */ mp_map_init(&kwargs, 0); mp_arg_parse_all(n_args, args_p, &kwargs, MP_ARRAY_SIZE(allowed_args), allowed_args, args); device = args[0].u_int; mode = args[1].u_int; if ((device < 0) || (device >= PIN_DEVICE_MAX)) { nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "bad pin device %d", device)); } if ((mode != PIN_INPUT) && (mode != PIN_OUTPUT)) { nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "bad pin mode %d", mode)); } /* Create a new Pin object. */ self_p = m_new0(struct class_pin_t, 1); self_p->base.type = &module_drivers_class_pin; if (pin_init((struct pin_driver_t *)&self_p->drv, &pin_device[device], mode) != 0) { return (mp_const_none); } return (self_p); }
void imu_init(void) { pin_init(&IMU_MOSI, (unsigned int *)&PORTB, (unsigned int *)&TRISB, (unsigned int *)NULL, 8, -1, 0, 8, (unsigned int *)&RPOR4); pin_init(&IMU_SCK, (unsigned int *)&PORTB, (unsigned int*)&TRISB, (unsigned int *)NULL, 9, -1, 8, 9, (unsigned int*)&RPOR4); pin_init(&IMU_MISO, (unsigned int *)&PORTB, (unsigned int *)&TRISB, (unsigned int *)NULL, 14, -1, 0, 14, (unsigned int *)&RPOR7); pin_init(&ACCEL_CS, (unsigned int*)&PORTB, (unsigned int *)&TRISB, (unsigned int *)NULL, 13, -1, 0, -1, (unsigned int *)NULL); pin_init(&GYRO_CS, (unsigned int *)&PORTB, (unsigned int *)&TRISB, (unsigned int *)NULL, 11, -1, 0, -1, (unsigned int *)NULL); pin_digitalOut(&ACCEL_CS); pin_digitalOut(&GYRO_CS); pin_set(&GYRO_CS); pin_set(&ACCEL_CS); spi_open(&spi1, &IMU_MISO, &IMU_MOSI, &IMU_SCK, 2e6); accel_write(I2CADD, 0x80); //Disable I2C }
int send_pulse(void) { if (state != ST_IDLE) return 0; pin_init(); PORTC |= (1 << PC5); // the leading edge of the pulse timer_init(); state = ST_SENDING_START_PULSE; return 1; }
int main() { struct nrf24l01_driver_t nrf24l01; struct pin_driver_t pin[3]; uint8_t state[32]; sys_start(); nrf24l01_init(&nrf24l01, &spi_device[0], &pin_d10_dev, &pin_d6_dev, &exti_device[1], SERVER_ADDRESS); nrf24l01_start(&nrf24l01); /* Initialize led pins. */ pin_init(&pin[0], &pin_d7_dev, PIN_OUTPUT); pin_init(&pin[1], &pin_d8_dev, PIN_OUTPUT); pin_init(&pin[2], &pin_d9_dev, PIN_OUTPUT); pin_write(&pin[0], 0); pin_write(&pin[1], 0); pin_write(&pin[2], 0); while (1) { /* Read state from client. */ nrf24l01_read(&nrf24l01, state, sizeof(state)); std_printf(FSTR("state = 0x%x\r\n"), (int)state[0]); /* Upadte LED. */ pin_write(&pin[0], (state[0] >> 0) & 0x1); pin_write(&pin[1], (state[0] >> 1) & 0x1); pin_write(&pin[2], (state[0] >> 2) & 0x1); } return (0); }
int main(void) { pin_init(); uart_init(); uart_set_rx_callback(&my_rx_callback); uart_enable(); sei(); while(1) { uart_send_data(ch_cycles, 4*CH_NUM); uart_send_data(ch_rpm, 2*CH_NUM); measure_rpm(); _delay_ms(1000); } }
int uart_soft_init(struct uart_soft_driver_t *self_p, struct pin_device_t *tx_dev_p, struct pin_device_t *rx_dev_p, struct exti_device_t *rx_exti_dev_p, int baudrate, void *rxbuf_p, size_t size) { ASSERTN(self_p != NULL, EINVAL); ASSERTN(tx_dev_p != NULL, EINVAL); ASSERTN(rx_dev_p != NULL, EINVAL); ASSERTN(rx_exti_dev_p != NULL, EINVAL); ASSERTN(rxbuf_p != NULL, EINVAL); self_p->sample_time = BAUDRATE2US(baudrate); chan_init(&self_p->chout, chan_read_null, (ssize_t (*)(void *, const void *, size_t))uart_soft_write_cb, chan_size_null); pin_init(&self_p->tx_pin, tx_dev_p, PIN_OUTPUT); pin_init(&self_p->rx_pin, rx_dev_p, PIN_INPUT); /* Keep TX line high when no transmission is ongoing. */ pin_write(&self_p->tx_pin, 1); exti_init(&self_p->rx_exti, rx_exti_dev_p, EXTI_TRIGGER_FALLING_EDGE, rx_isr, self_p); exti_start(&self_p->rx_exti); return (queue_init(&self_p->chin, rxbuf_p, size)); }
int board_init() { gd->bd->bi_arch_number = MACH_TYPE_OPENPHONE; gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100; misc_init(); ADI_init(); LDO_Init(); ADC_Init(); pin_init(); sprd_eic_init(); sprd_gpio_init(); sound_init(); TDPllRefConfig(1); return 0; }
int board_init() { gd->bd->bi_arch_number = MACH_TYPE_OPENPHONE; gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100; #if 0 ADI_init(); chip_init(); LDO_Init(); sprd_gpio_init(); //board_gpio_init(); #endif pin_init(); sprd_gpio_init(sprd_gpio_resource); sound_init(); return 0; }
int board_init() { gd->bd->bi_arch_number = MACH_TYPE_OPENPHONE; gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100; ADI_init(); misc_init(); LDO_Init(); ADC_Init(); pin_init(); sprd_eic_init(); sprd_gpio_init(); sound_init(); init_ldo_sleep_gr(); //cp2_rfctl_init(); return 0; }
void main(void) { __delay_ms(100); pin_init(); //I/Oの初期化 while(1) { if(RA0 == 1) { //RA0がHIGH(通電)なら1を送る while(TXIF == 0){} TXREG = 1; __delay_ms(1000); } else { //RA0がLOWなら0を送る while(TXIF == 0){} TXREG = 0; __delay_ms(1000); } } }
int main() { struct pin_driver_t led; /* Start the system. */ sys_start(); /* Initialize the LED pin as output and set its value to 1. */ pin_init(&led, &pin_led_dev, PIN_OUTPUT); pin_write(&led, 1); while (1) { /* Wait half a second. */ thrd_sleep_us(500000); /* Toggle the LED on/off. */ pin_toggle(&led); } return (0); }
int main(void) { serial_init(); pin_init(); twi_init(); sensor_calib_first(); value = 157; pwm_init(); L3G_init(1); L3G_enableDefault(); LSM303_init(1); LSM303_enableDefault(); LPS_init(1); LPS_enableDefault(); receiveready = 1; while(1 == 1) { if(receivecomplete == 1) { analise_command(); receivecomplete = 0; receiveready = 1; recvcount = 0; } if(tmr_int == 1) { control(); } } return 0; }
int main(void) { pid_t pid; pid = getpid(); if (pid > 0){ //printf("\nPID Parent= %d\n", pid); //return 0; } if (pid == 0){ //printf("\nPID child = %d\n", pid); return 0; } /* uinput init */ int i,fd; struct uinput_user_dev device; memset(&device, 0, sizeof device); fd=open("/dev/uinput",O_WRONLY); strcpy(device.name,"test keyboard"); device.id.bustype=BUS_USB; device.id.vendor=1; device.id.product=1; device.id.version=1; if (write(fd,&device,sizeof(device)) != sizeof(device)) { fprintf(stderr, "error setup\n"); } if (ioctl(fd,UI_SET_EVBIT,EV_KEY) < 0) fprintf(stderr, "error evbit key\n"); for (i=0;i<70;i++) if (ioctl(fd,UI_SET_KEYBIT, abc[i]) < 0) fprintf(stderr, "error evbit key\n"); if (ioctl(fd,UI_SET_EVBIT,EV_REL) < 0) fprintf(stderr, "error evbit rel\n"); for(i=REL_X;i<REL_MAX;i++) if (ioctl(fd,UI_SET_RELBIT,i) < 0) fprintf(stderr, "error setrelbit %d\n", i); if (ioctl(fd,UI_DEV_CREATE) < 0) { fprintf(stderr, "error create\n"); } sleep(2); /* end uinput init */ /* init event0 */ int fdkey; fdkey = open("/dev/input/event0", O_RDONLY); // struct input_event evkey; int flags = fcntl(fd, F_GETFL, 0); //int err; fcntl(fdkey, F_SETFL, flags | O_NONBLOCK); /* end init event0 */ pin_init(); //int j, m=0,k; int returnKeyPress = 0; while(1) { /* check for key */ // k=0; // err=-1; // while ((err==-1) && (k<500)) { // err = read(fdkey, &evkey, sizeof(struct input_event)); // k++; // usleep(1000); // } // // if (err!=-1) { // if ((evkey.type==1) && (evkey.value==0)) { // // if ((m==27) || (m==28)) break; // send_event(fd, EV_KEY, abc[m], 1); // send_event(fd, EV_SYN, SYN_REPORT, 0); // send_event(fd, EV_KEY, abc[m], 0); // send_event(fd, EV_SYN, SYN_REPORT, 0); // } else { // if (m==0) // m=27; // else // m--; // } // //printf("%i",m); // } returnKeyPress = get_key(); // if ( returnKeyPress != -1 ){ send_event(fd, EV_KEY, abc[returnKeyPress], 1); send_event(fd, EV_SYN, SYN_REPORT, 0); send_event(fd, EV_KEY, abc[returnKeyPress], 0); send_event(fd, EV_SYN, SYN_REPORT, 0); } } close(fd); return 0; }
int main(int argc, char** argv) { uint32_t led_colors = 0; uint8_t at_parm_test[10]; unsigned once; uint32_t i = 0; uint8_t canPrescaler = 0; uint8_t* uart_tx_packet = 0; uint8_t* uart_rx_packet; uint32_t old_loadcell_data; uint16_t timeStep = 1; clock_init(); pin_init(); led_init(); timers_init(); state_init(); uart_init(); // Set up UART2 for 115200 baud. There's no round() on the dsPICs, so we implement our own. double brg = (double) 140000000 / 2.0 / 16.0 / 115200.0 - 1.0; if (brg - floor(brg) >= 0.5) { brg = ceil(brg); } else { brg = floor(brg); } // Uart2Init (brg); // Init UART 2 as 115200 baud/s loadcell_init(); loadcell_start(); led_rgb_off(); led_rgb_set(50, 0, 100); can_state.init_return = RET_UNKNOWN; if (can_init()) { while (1); } timer_state.prev_systime = 0; timer_state.systime = 0; #ifdef CONF71 // Start Reading the int pin on IMU mpuData.startData = 0; if (IMU_Init(400000, 70000000) == 0) { // imu_state.init_return = RET_OK; mpuData.startData = 1; } else { //imu_state.init_return = RET_ERROR; } #endif for (;;) { if (timer_state.systime != timer_state.prev_systime) { timer_state.prev_systime = timer_state.systime; //everything in here will be executed once every ms //make sure that everything in here takes less than 1ms //useful for checking state consistency, synchronization, watchdog... if(timer_state.systime % 1000 == 1) { LED_4 = 1; } led_update(); if (timer_state.systime % 10 == 1) { IMU_GetQuaternion(quaterion); QuaternionToYawPitchRoll(quaterion, ypr); } if (timer_state.systime % 5 == 1) { IMU_normalizeData(&mpuData, &magData, &imuData); // Run AHRS algorithm IMU_UpdateAHRS (&imuData); // Run IMU algorithm (does not use MAG data) // IMU_UpdateIMU(&imuData); //copy state to CAN dictionary IMU_CopyOutput(&imuData, &mpuData, &magData); } /** * CANFestival Loop */ if (can_state.init_return == RET_OK) { can_process(); /** * Sets CANFestival shared variables * specific to Sensor Board */ can_push_state(); } /** * Blinking LED Loop */ if (timer_state.systime % 25 == 0) { LED_1 = !LED_1; } } else { //untimed processes in main loop: //executed as fast as possible //these processes should NOT block the main loop // LED_4 = mpuData.accelX > 0; // LED_3 = mpuData.accelY > 0; // LED_1 = mpuData.accelZ > 0; // IMU_GetData(); IMU_CopyI2CData(&mpuData, &magData); if (!T1CONbits.TON) { RGB_RED = 0; RGB_GREEN = RGB_BLUE = 1; while (1); } if(can_flag){ TimeDispatch(); can_flag = 0; } uart_rx_packet = uart_rx_cur_packet(); if (uart_rx_packet != 0) { uart_rx_packet_consumed(); } /** * Handles CAN transmission buffers */ if ((txreq_bitarray & 0b00000001) && !C1TR01CONbits.TXREQ0) { C1TR01CONbits.TXREQ0 = 1; txreq_bitarray = txreq_bitarray & 0b11111110; } if ((txreq_bitarray & 0b00000010) && !C1TR01CONbits.TXREQ1) { C1TR01CONbits.TXREQ1 = 1; txreq_bitarray = txreq_bitarray & 0b11111101; } if ((txreq_bitarray & 0b00000100) && !C1TR23CONbits.TXREQ2) { C1TR23CONbits.TXREQ2 = 1; txreq_bitarray = txreq_bitarray & 0b11111011; } if ((txreq_bitarray & 0b00001000) && !C1TR23CONbits.TXREQ3) { C1TR23CONbits.TXREQ3 = 1; txreq_bitarray = txreq_bitarray & 0b11110111; } if ((txreq_bitarray & 0b00010000) && !C1TR45CONbits.TXREQ4) { C1TR45CONbits.TXREQ4 = 1; txreq_bitarray = txreq_bitarray & 0b11101111; } if ((txreq_bitarray & 0b00100000) && !C1TR45CONbits.TXREQ5) { C1TR45CONbits.TXREQ5 = 1; txreq_bitarray = txreq_bitarray & 0b11011111; } if ((txreq_bitarray & 0b01000000) && !C1TR67CONbits.TXREQ6) { C1TR67CONbits.TXREQ6 = 1; txreq_bitarray = txreq_bitarray & 0b10111111; } } } return (EXIT_SUCCESS); }
void init_74hc595(void) { pin_init(); }
int main (void) { int t, firstrun; volatile int i; /* Initialize GPIO (sets up clock) */ GPIOInit (); /* initialize pins */ pin_init (); /* setup SPI chipselect pins */ spi_init_pin (SPI_CS_NRF); /* blink as a sign of boot to detect crashes */ for (t = 0; t < 10; t++) { pin_led (GPIO_LED0); for (i = 0; i < 100000; i++); pin_led (GPIO_LEDS_OFF); for (i = 0; i < 100000; i++); } /* Init USB HID interface */ hid_init (); /* Init SPI */ spi_init (); /* Init OpenBeacon nRF24L01 interface */ nRFAPI_Init (81, broadcast_mac, sizeof (broadcast_mac), 0); /* Init 3D acceleration sensor */ acc_init (); /* Init Storage */ storage_init (); /* Init Bluetooth */ bt_init (); /* main loop */ t = 0; firstrun = 1; while (1) { /* blink LED0 on every 32th run - FIXME later with sleep */ if ((t++ & 0x1F) == 0) { pin_led (GPIO_LED0); for (i = 0; i < 100000; i++); pin_led (GPIO_LEDS_OFF); } for (i = 0; i < 200000; i++); if (UARTCount) { /* blink LED1 upon Bluetooth command */ pin_led (GPIO_LED1); /* show help screen upon Bluetooth connect */ if (firstrun) { debug_printf ("press 'H' for help...\n# "); firstrun = 0; } else /* execute menue command with last character received */ main_menue (UARTBuffer[UARTCount - 1]); /* LED1 off again */ pin_led (GPIO_LEDS_OFF); /* clear UART buffer */ UARTCount = 0; } } }
int main(int argc, char *argv[]) { char buf[50], // For sundry filenames c, // Pin input value ('0'/'1') board; // 0=Pi1Rev1, 1=Pi1Rev2, 2=Pi2 int key, fd, // For mmap, sysfs, uinput i, j, // Asst. counter bitmask; // Pullup enable bitmask unsigned long bitMask, bit; // For Vulcan pinch detect volatile unsigned char shortWait; // Delay counter struct input_event keyEv, synEv; // uinput events //struct pollfd p[32]; // GPIO file descriptors progName = argv[0]; // For error reporting // Select io[] table for orientation. 0 or 90 // io = (access("/etc/modprobe.d/adafruit.conf", F_OK) || // access("/dev/fb1", F_OK)) ? ioStandard : ioTFT; io = io_0; pin_init(); int returnKeyPress_00 = 0; int returnKeyPress_01 = 0; // Normally uses /dev/uinput for generating key events. if((fd = open("/dev/uinput", O_WRONLY | O_NONBLOCK)) < 0) err("Can't open /dev/uinput"); if(ioctl(fd, UI_SET_EVBIT, EV_KEY) < 0) err("Can't SET_EVBIT"); for(i=0; io[i].button >= 0; i++) { if(io[i].key != GND) { if(ioctl(fd, UI_SET_KEYBIT, io[i].key) < 0) err("Can't SET_KEYBIT"); } } struct uinput_user_dev uidev; memset(&uidev, 0, sizeof(uidev)); snprintf(uidev.name, UINPUT_MAX_NAME_SIZE, "Keypad_Driver"); uidev.id.bustype = BUS_USB; uidev.id.vendor = 0x1; uidev.id.product = 0x1; uidev.id.version = 1; if(write(fd, &uidev, sizeof(uidev)) < 0) err("write failed"); if(ioctl(fd, UI_DEV_CREATE) < 0) err("DEV_CREATE failed"); // Initialize input event structures memset(&keyEv, 0, sizeof(keyEv)); keyEv.type = EV_KEY; memset(&synEv, 0, sizeof(synEv)); synEv.type = EV_SYN; synEv.code = SYN_REPORT; synEv.value = 0; // 'fd' is now open file descriptor for issuing uinput events while(running) { returnKeyPress_00 = get_key(); // std::cout << "\t\tButton press = " << returnKeyPress << "\n"; keyEv.code = io[returnKeyPress_01].key; keyEv.value = 1; write(fd, &keyEv, sizeof(keyEv)); delay(180); keyEv.value = 0; write(fd, &keyEv, sizeof(keyEv)); } return 0; }
int main(void) { // TODO disable JTAG /* STM32F4xx HAL library initialization: - Configure the Flash prefetch, instruction and Data caches - Configure the Systick to generate an interrupt each 1 msec - Set NVIC Group Priority to 4 - Global MSP (MCU Support Package) initialization */ HAL_Init(); // set the system clock to be HSE SystemClock_Config(); // enable GPIO clocks __GPIOA_CLK_ENABLE(); __GPIOB_CLK_ENABLE(); __GPIOC_CLK_ENABLE(); __GPIOD_CLK_ENABLE(); // enable the CCM RAM __CCMDATARAMEN_CLK_ENABLE(); #if 0 #if defined(NETDUINO_PLUS_2) { GPIO_InitTypeDef GPIO_InitStructure; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_25MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; #if MICROPY_HW_HAS_SDCARD // Turn on the power enable for the sdcard (PB1) GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1; GPIO_Init(GPIOB, &GPIO_InitStructure); GPIO_WriteBit(GPIOB, GPIO_Pin_1, Bit_SET); #endif // Turn on the power for the 5V on the expansion header (PB2) GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; GPIO_Init(GPIOB, &GPIO_InitStructure); GPIO_WriteBit(GPIOB, GPIO_Pin_2, Bit_SET); } #endif #endif // basic sub-system init pendsv_init(); timer_tim3_init(); led_init(); #if MICROPY_HW_HAS_SWITCH switch_init0(); #endif int first_soft_reset = true; soft_reset: // check if user switch held to select the reset mode led_state(1, 0); led_state(2, 1); led_state(3, 0); led_state(4, 0); uint reset_mode = 1; #if MICROPY_HW_HAS_SWITCH if (switch_get()) { for (uint i = 0; i < 3000; i++) { if (!switch_get()) { break; } HAL_Delay(20); if (i % 30 == 29) { if (++reset_mode > 3) { reset_mode = 1; } led_state(2, reset_mode & 1); led_state(3, reset_mode & 2); led_state(4, reset_mode & 4); } } // flash the selected reset mode for (uint i = 0; i < 6; i++) { led_state(2, 0); led_state(3, 0); led_state(4, 0); HAL_Delay(50); led_state(2, reset_mode & 1); led_state(3, reset_mode & 2); led_state(4, reset_mode & 4); HAL_Delay(50); } HAL_Delay(400); } #endif #if MICROPY_HW_ENABLE_RTC if (first_soft_reset) { rtc_init(); } #endif // more sub-system init #if MICROPY_HW_HAS_SDCARD if (first_soft_reset) { sdcard_init(); } #endif if (first_soft_reset) { storage_init(); } // GC init gc_init(&_heap_start, &_heap_end); // Change #if 0 to #if 1 if you want REPL on UART_6 (or another uart) // as well as on USB VCP #if 0 { mp_obj_t args[2] = { MP_OBJ_NEW_SMALL_INT(PYB_UART_6), MP_OBJ_NEW_SMALL_INT(115200), }; pyb_uart_global_debug = pyb_uart_type.make_new((mp_obj_t)&pyb_uart_type, ARRAY_SIZE(args), 0, args); } #else pyb_uart_global_debug = NULL; #endif // Micro Python init qstr_init(); mp_init(); mp_obj_list_init(mp_sys_path, 0); mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR_0_colon__slash_)); mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR_0_colon__slash_lib)); mp_obj_list_init(mp_sys_argv, 0); readline_init(); pin_init(); extint_init(); #if MICROPY_HW_HAS_LCD // LCD init (just creates class, init hardware by calling LCD()) lcd_init(); #endif // local filesystem init { // try to mount the flash FRESULT res = f_mount(&fatfs0, "0:", 1); if (reset_mode == 3 || res == FR_NO_FILESYSTEM) { // no filesystem, or asked to reset it, so create a fresh one // LED on to indicate creation of LFS led_state(PYB_LED_R2, 1); uint32_t start_tick = HAL_GetTick(); res = f_mkfs("0:", 0, 0); if (res == FR_OK) { // success creating fresh LFS } else { __fatal_error("could not create LFS"); } // create empty main.py FIL fp; f_open(&fp, "0:/main.py", FA_WRITE | FA_CREATE_ALWAYS); UINT n; f_write(&fp, fresh_main_py, sizeof(fresh_main_py) - 1 /* don't count null terminator */, &n); // TODO check we could write n bytes f_close(&fp); // create .inf driver file f_open(&fp, "0:/pybcdc.inf", FA_WRITE | FA_CREATE_ALWAYS); f_write(&fp, fresh_pybcdc_inf, sizeof(fresh_pybcdc_inf) - 1 /* don't count null terminator */, &n); f_close(&fp); // create readme file f_open(&fp, "0:/README.txt", FA_WRITE | FA_CREATE_ALWAYS); f_write(&fp, fresh_readme_txt, sizeof(fresh_readme_txt) - 1 /* don't count null terminator */, &n); f_close(&fp); // keep LED on for at least 200ms sys_tick_wait_at_least(start_tick, 200); led_state(PYB_LED_R2, 0); } else if (res == FR_OK) { // mount sucessful } else { __fatal_error("could not access LFS"); } } // make sure we have a 0:/boot.py { FILINFO fno; #if _USE_LFN fno.lfname = NULL; fno.lfsize = 0; #endif FRESULT res = f_stat("0:/boot.py", &fno); if (res == FR_OK) { if (fno.fattrib & AM_DIR) { // exists as a directory // TODO handle this case // see http://elm-chan.org/fsw/ff/img/app2.c for a "rm -rf" implementation } else { // exists as a file, good! } } else { // doesn't exist, create fresh file // LED on to indicate creation of boot.py led_state(PYB_LED_R2, 1); uint32_t start_tick = HAL_GetTick(); FIL fp; f_open(&fp, "0:/boot.py", FA_WRITE | FA_CREATE_ALWAYS); UINT n; f_write(&fp, fresh_boot_py, sizeof(fresh_boot_py) - 1 /* don't count null terminator */, &n); // TODO check we could write n bytes f_close(&fp); // keep LED on for at least 200ms sys_tick_wait_at_least(start_tick, 200); led_state(PYB_LED_R2, 0); } } // root device defaults to internal flash filesystem uint root_device = 0; #if defined(USE_DEVICE_MODE) usb_storage_medium_t usb_medium = USB_STORAGE_MEDIUM_FLASH; #endif #if MICROPY_HW_HAS_SDCARD // if an SD card is present then mount it on 1:/ if (reset_mode == 1 && sdcard_is_present()) { FRESULT res = f_mount(&fatfs1, "1:", 1); if (res != FR_OK) { printf("[SD] could not mount SD card\n"); } else { // use SD card as root device root_device = 1; if (first_soft_reset) { // use SD card as medium for the USB MSD #if defined(USE_DEVICE_MODE) usb_medium = USB_STORAGE_MEDIUM_SDCARD; #endif } } } #else // Get rid of compiler warning if no SDCARD is configured. (void)first_soft_reset; #endif // run <root>:/boot.py, if it exists if (reset_mode == 1) { const char *boot_file; if (root_device == 0) { boot_file = "0:/boot.py"; } else { boot_file = "1:/boot.py"; } FRESULT res = f_stat(boot_file, NULL); if (res == FR_OK) { if (!pyexec_file(boot_file)) { flash_error(4); } } } // turn boot-up LEDs off led_state(2, 0); led_state(3, 0); led_state(4, 0); #if defined(USE_HOST_MODE) // USB host pyb_usb_host_init(); #elif defined(USE_DEVICE_MODE) // USB device if (reset_mode == 1) { usb_device_mode_t usb_mode = USB_DEVICE_MODE_CDC_MSC; if (pyb_config_usb_mode != MP_OBJ_NULL) { if (strcmp(mp_obj_str_get_str(pyb_config_usb_mode), "CDC+HID") == 0) { usb_mode = USB_DEVICE_MODE_CDC_HID; } } pyb_usb_dev_init(usb_mode, usb_medium); } else { pyb_usb_dev_init(USB_DEVICE_MODE_CDC_MSC, usb_medium); } #endif timer_init0(); #if MICROPY_HW_ENABLE_RNG rng_init0(); #endif i2c_init0(); spi_init0(); #if MICROPY_HW_HAS_MMA7660 // MMA accel: init and reset accel_init(); #endif #if MICROPY_HW_ENABLE_SERVO // servo servo_init(); #endif #if MICROPY_HW_ENABLE_DAC // DAC dac_init(); #endif // now that everything is initialised, run main script if (reset_mode == 1 && pyexec_mode_kind == PYEXEC_MODE_FRIENDLY_REPL) { vstr_t *vstr = vstr_new(); vstr_printf(vstr, "%d:/", root_device); if (pyb_config_main == MP_OBJ_NULL) { vstr_add_str(vstr, "main.py"); } else { vstr_add_str(vstr, mp_obj_str_get_str(pyb_config_main)); } FRESULT res = f_stat(vstr_str(vstr), NULL); if (res == FR_OK) { if (!pyexec_file(vstr_str(vstr))) { flash_error(3); } } vstr_free(vstr); } #if MICROPY_HW_ENABLE_CC3K // wifi using the CC3000 driver pyb_wlan_init(); pyb_wlan_start(); #endif // enter REPL // REPL mode can change, or it can request a soft reset for (;;) { if (pyexec_mode_kind == PYEXEC_MODE_RAW_REPL) { if (pyexec_raw_repl() != 0) { break; } } else { if (pyexec_friendly_repl() != 0) { break; } } } printf("PYB: sync filesystems\n"); storage_flush(); printf("PYB: soft reboot\n"); first_soft_reset = false; goto soft_reset; }
int main (void) { /* accelerometer readings fifo */ TFifoEntry acc_lowpass; TFifoEntry fifo_buf[FIFO_DEPTH]; int fifo_pos; TFifoEntry *fifo; uint32_t SSPdiv; uint16_t oid_last_seen; uint8_t cmd_buffer[64], cmd_pos, c; uint8_t volatile *uart; int x, y, z, moving; volatile int t; int i; /* wait on boot - debounce */ for (t = 0; t < 2000000; t++); /* Initialize GPIO (sets up clock) */ GPIOInit (); /* initialize pins */ pin_init (); /* fire up LED 1 */ GPIOSetValue (1, 1, 1); /* initialize SPI */ spi_init (); /* read device UUID */ bzero (&device_uuid, sizeof (device_uuid)); iap_read_uid (&device_uuid); tag_id = crc16 ((uint8_t *) & device_uuid, sizeof (device_uuid)); random_seed = device_uuid[0] ^ device_uuid[1] ^ device_uuid[2] ^ device_uuid[3]; /************ IF Plugged to computer upon reset ? ******************/ if (GPIOGetValue (0, 3)) { /* wait some time till Bluetooth is off */ for (t = 0; t < 2000000; t++); /* Init 3D acceleration sensor */ acc_init (1); /* Init Flash Storage with USB */ storage_init (TRUE, tag_id); g_storage_items = storage_items (); /* Init Bluetooth */ bt_init (TRUE, tag_id); /* switch to LED 2 */ GPIOSetValue (1, 1, 0); GPIOSetValue (1, 2, 1); /* set command buffer to empty */ cmd_pos = 0; /* spin in loop */ while (1) { /* reset after USB unplug */ if (!GPIOGetValue (0, 3)) NVIC_SystemReset (); /* if UART rx send to menue */ if (UARTCount) { /* blink LED1 upon Bluetooth command */ GPIOSetValue (1, 1, 1); /* execute menue command with last character received */ /* scan through whole UART buffer */ uart = UARTBuffer; for (i = UARTCount; i > 0; i--) { UARTCount--; c = *uart++; if ((c < ' ') && cmd_pos) { /* if one-character command - execute */ if (cmd_pos == 1) main_menue (cmd_buffer[0]); else { cmd_buffer[cmd_pos] = 0; debug_printf ("Unknown command '%s' - please press H+[Enter] for help\n# ", cmd_buffer); } /* set command buffer to empty */ cmd_pos = 0; } else if (cmd_pos < (sizeof (cmd_buffer) - 2)) cmd_buffer[cmd_pos++] = c; } /* reset UART buffer */ UARTCount = 0; /* un-blink LED1 */ GPIOSetValue (1, 1, 0); } } } /* End of if plugged to computer*/ /***************** IF UNPLUGGED TO PC ........********/ /* Init Bluetooth */ bt_init (FALSE, tag_id); /* shut down up LED 1 */ GPIOSetValue (1, 1, 0); /* Init Flash Storage without USB */ storage_init (FALSE, tag_id); /* get current FLASH storage write postition */ g_storage_items = storage_items (); /* initialize power management */ pmu_init (); /* blink once to show initialized flash */ blink (1); /* Init 3D acceleration sensor */ acc_init (0); blink (2); /* Initialize OpenBeacon nRF24L01 interface */ if (!nRFAPI_Init(CONFIG_TRACKER_CHANNEL, broadcast_mac, sizeof (broadcast_mac), 0)) for (;;) { GPIOSetValue (1, 2, 1); pmu_sleep_ms (500); GPIOSetValue (1, 2, 0); pmu_sleep_ms (500); } /* set tx power power to high */ nRFCMD_Power (1); /* blink three times to show flash initialized RF interface */ blink (3); /* blink LED for 1s to show readyness */ GPIOSetValue (1, 1, 0); GPIOSetValue (1, 2, 1); pmu_sleep_ms (1000); GPIOSetValue (1, 2, 0); /* disable unused jobs */ SSPdiv = LPC_SYSCON->SSPCLKDIV; i = 0; oid_last_seen = 0; /* reset proximity buffer */ prox_head = prox_tail = 0; bzero (&prox, sizeof (prox)); /*initialize FIFO */ fifo_pos = 0; bzero (&acc_lowpass, sizeof (acc_lowpass)); bzero (&fifo_buf, sizeof (fifo_buf)); moving = 0; g_sequence = 0; while (1) { pmu_sleep_ms (500); LPC_SYSCON->SSPCLKDIV = SSPdiv; acc_power (1); pmu_sleep_ms (20); acc_xyz_read (&x, &y, &z); acc_power (0); fifo = &fifo_buf[fifo_pos]; if (fifo_pos >= (FIFO_DEPTH - 1)) fifo_pos = 0; else fifo_pos++; acc_lowpass.x += x - fifo->x; fifo->x = x; acc_lowpass.y += y - fifo->y; fifo->y = y; acc_lowpass.z += z - fifo->z; fifo->z = z; nRFAPI_SetRxMode (0); bzero (&g_Beacon, sizeof (g_Beacon)); g_Beacon.pkt.proto = RFBPROTO_BEACONTRACKER_EXT; g_Beacon.pkt.flags = moving ? RFBFLAGS_MOVING : 0; g_Beacon.pkt.oid = htons (tag_id); g_Beacon.pkt.p.tracker.strength = (i & 1) + TX_STRENGTH_OFFSET; g_Beacon.pkt.p.tracker.seq = htonl (LPC_TMR32B0->TC); g_Beacon.pkt.p.tracker.oid_last_seen = oid_last_seen; g_Beacon.pkt.p.tracker.time = htons ((uint16_t)g_sequence++); g_Beacon.pkt.p.tracker.battery = 0; g_Beacon.pkt.crc = htons ( crc16(g_Beacon.byte, sizeof (g_Beacon) - sizeof (g_Beacon.pkt.crc)) ); nRFCMD_Power (0); nRF_tx (g_Beacon.pkt.p.tracker.strength); nRFCMD_Power (1); nRFAPI_PowerDown (); LPC_SYSCON->SSPCLKDIV = 0x00; blink (10); } return 0; }