int main(void) { clock_init(); serial_init(9600); nrf_init(); cio_print("nRF2401 v0.1, TestClient\n\r"); nrf_configure_esb_rx(); nrf_dump_regs(&nrf_reg_def); static nrf_payload p; int s; // set payload size according to the payload size configured for the RX channel p.size = 1; while (1) { s = nrf_receive_blocking(&p); cio_printf("Received payload: %x; bytes received: %u\n\r", p.data[0], s); } return 0; }
int shell_cmd_argt(shell_cmd_args *args) { int k; cio_print((char *)"args given:\n\r"); for(k = 0; k < args->count; k++) { cio_printf(" - %s\n\r", args->args[k].val); } return 0; }
int shell_cmd_encr(shell_cmd_args *args) { if(args->count == 0) { cio_print((char *) "ERROR, no string to encrypt\n\r"); return -1; } if(strlen(args->args[0].val) > 20) { cio_print((char *) "ERROR, string to encrypt is too long\n\r"); return -1; } int k; char string[21]; strncpy(string, args->args[0].val, 20); for(k = 0; k < strlen(string); k++) { string[k] = string[k] ^ key[k]; } cio_printf("encrypted string: %s\n\r", string); return 0; }
void nrf_dump_regs(nrf_regs *r) { int i; int j; cio_print("\n\r** START nRF2401 Register DUMP **\n\r"); nrf_reg_buf buf; for(i = 0; i < r->count; i++) { nrf_read_reg(i, &buf); if(r->data[i].size == 0) continue; cio_printf("%s: ", r->data[i].name); for(j = 0; j < buf.size; j++) { cio_printb(buf.data[j], 8); cio_printf(" (%u) ", buf.data[j]); } cio_print("\n\r - "); for(j = 0; j < r->data[i].fields->count; j++) { cio_printf("%u[%u]:%s=%u ", j, r->data[i].fields->data[j].size, r->data[i].fields->data[j].name, nrf_get_reg_field(i, j, &buf)); } cio_print("-\n\r"); } cio_print("** END nRF2401 Register DUMP **\n\r"); }
/******************************************* INITIALIZE *******************************************/ int main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer BCSCTL1 = CALBC1_1MHZ; DCOCTL = CALDCO_1MHZ; serial_init(9600); __dint(); // Enable global interrupts /******************************************* MAIN LOOP *******************************************/ for(;;) { int j = 0; // Char array counter char cmd_line[90] = { 0 }; // Init empty array cio_print((char *) "$ "); // Display prompt char c = cio_getc(); // Wait for a character while(c != '\r') { // until return sent then ... if(c == 0x08) { // was it the delete key? if(j != 0) { // cursor NOT at start? cmd_line[--j] = 0; // delete key logic cio_printc(0x08); cio_printc(' '); cio_printc(0x08); } } else { // otherwise ... cmd_line[j++] = c; cio_printc(c); // echo received char } c = cio_getc(); // Wait for another } cio_print((char *) "\n\n\r"); // Delimit command result switch(shell_process(cmd_line)) // Execute specified shell command { // and handle any errors case SHELL_PROCESS_ERR_CMD_UNKN: cio_print((char *) "ERROR, unknown command given\n\r"); break; case SHELL_PROCESS_ERR_ARGS_LEN: cio_print((char *) "ERROR, an arguement is too lengthy\n\r"); break; case SHELL_PROCESS_ERR_ARGS_MAX: cio_print((char *) "ERROR, too many arguements given\n\r"); break; default: break; } cio_print((char *) "\n"); // Delimit before prompt } return 0; }
int shell_cmd_move(shell_cmd_args *args) { unsigned int x = shell_parse_int(args->args[0].val); //parse x cordinate unsigned int y = shell_parse_int(args->args[1].val); //parse y cordinate //See if a valid degree is choosen if((x>MAX_DUTYCYCLE || x<MIN_DUTYCYCLE) || (y>(MAX_DUTYCYCLE/2) || y<MIN_DUTYCYCLE)) { //cio_printf("Invalid position. Please input an integer between 600 and 2600\n\r"); //return 0; } TA0CCR1 = x; TA1CCR1 = y; cio_print("Move Successful.\n\r"); return 0; }
int main(void) { clock_init(); serial_init(9600); exti_init(); nrf_init(); cio_print("nRF2401 v0.1 - TestClient ESBPL-exti\n\r"); nrf_configure_esbpl_rx(); // setup payload prx.size = 1; // receive payload size 1Byte ptx.size = 1; // send payload size 1Byte ptx.data[0] = 0; // set payload to 0 // Nothing to do here since ISR does all the work while (1) { __asm__("nop"); } return 0; }
/******************************************* INITIALIZE *******************************************/ void main(void) { //Basic prep WDTCTL = WDTPW + WDTHOLD; //Stop Watchdog TImer BCSCTL1 = CALBC1_1MHZ; //Clocks DCOCTL = CALDCO_1MHZ; P1REN = BIT3; //turn on pull-resistor on 0b0001000 P1OUT |= BIT3; //powers pin3 (button) P1IE = BIT3; //enables p1 interrupt on pin 1.3 P1IES |= BIT3; //sets interrupt on high to low P1IFG &= ~BIT3; //clears interrupt flag //Prep 1st PWM channel (X AXIS) TA0CCTL1 = OUTMOD_7; // TA0CCR1 reset/set TA0CTL = TASSEL_2 + MC_1; // SMCLK + upmode //upmode(MC_1): the Timer repeatedly counts from 0 to the value set in register TACCR0) TACCR0 = PWM_PRD-1; //set pwm period TACCR1 = 0; //set TA0CCR1 PWM Duty Cycle P1DIR |= BIT6; //Pin 1.6 set as output P1SEL |= BIT6; //Set Pin 1.6 for pwm use //Prep 2nd PWM channel (Y AXIS) TA1CCTL1 = OUTMOD_7; //set/reset mode TA1CTL = TASSEL_2 + MC_1; //SMCLK + upmode TA1CCR0 = PWM_PRD-1; //set pwm period TA1CCR1 = 0; //set TA0CCR1_ pwm duty cycle P2DIR |= BIT2 | BIT3; //set as output P2OUT |= BIT2; P2SEL |= BIT2; //Set pin 2.2 for pwm use serial_init(9600); // set serial clockrate __enable_interrupt(); // Enable global interrupts /******************************************* MAIN LOOP *******************************************/ for(;;) { int j = 0; // Char array counter char cmd_line[255] = {0}; // Init empty array cio_print((char *) "$ "); // Display prompt char c = cio_getc(); // Wait for a character while(c != '\r') { // until return sent then ... if(c == 0x08) { // was it the delete key? if(j != 0) { // cursor NOT at start? cmd_line[--j] = 0; cio_printc(0x08); cio_printc(' '); cio_printc(0x08); } // delete key logic } else { // otherwise ... cmd_line[j++] = c; cio_printc(c); // echo received char } c = cio_getc(); // Wait for another } cio_print((char *) "\n\n\r"); // Delimit command result switch(shell_process(cmd_line)) // Execute specified shell command { // and handle any errors case SHELL_PROCESS_ERR_CMD_UNKN: cio_print((char *) "ERROR, unknown command given\n\r"); break; case SHELL_PROCESS_ERR_ARGS_LEN: cio_print((char *) "ERROR, an arguement is too lengthy\n\r"); break; case SHELL_PROCESS_ERR_ARGS_MAX: cio_print((char *) "ERROR, too many arguements given\n\r"); break; default: break; } cio_print((char *) "\n"); // Delimit before prompt } }
int main(void) { /* Initialize Leds mounted on STM32F0-discovery */ STM_EVAL_LEDInit(LED3); STM_EVAL_LEDInit(LED4); /* Turn on LED3 and LED4 */ STM_EVAL_LEDOn(LED3); STM_EVAL_LEDOn(LED4); /* Initialize other outputs and inputs */ STM_EVAL_LEDInit(RELAIS1); STM_EVAL_LEDInit(RELAIS2); STM_EVAL_LEDInit(OUT_12V_1); STM_EVAL_LEDInit(OUT_12V_2); STM_EVAL_PBInit(IN_12V_1, BUTTON_MODE_PDOWN); STM_EVAL_PBInit(IN_12V_2, BUTTON_MODE_PDOWN); /* Initialize the User_Button */ STM_EVAL_PBInit(BUTTON_USER, BUTTON_MODE_EXTI); /* Setup SysTick Timer for 1 msec interrupts. */ if (SysTick_Config(SystemCoreClock / 1000)) { /* Capture error */ while (1); } usart_1_init(); #ifndef WIFI_CONNECTED /* Output a message on Hyperterminal using printf function */ cio_printf("%s", welcome_msg); #else wifi_intit_pins(); wifi_init_connections(); // If the button is pressed on power on, // do not init the WiFi module to keep current WiFi connections // and save development time if (!STM_EVAL_PBGetState(BUTTON_USER)) wifi_init_ap_mode(); #endif while (1) { // Everything should be non-blocking #ifndef WIFI_CONNECTED if (serve_command_promt(line_buffer, LINEBUFFERSIZE, "microcli> ") > 0) { shell_process(line_buffer); } #else if (wifi_get_msg(line_buffer, LINEBUFFERSIZE, &cid) > 0) { bool add_header = (cid != -1); // send back to the current connection if (add_header) { cio_printf("\x1bS%c", cid); cio_printf("microcli> %s\r\n", line_buffer); } shell_process(line_buffer); if (add_header) { cio_print("[end]\r\n"); cio_print("\x1b" "E"); } } #endif if (timeout_0 == 0) { static uint8_t counter = 0; switch (counter++) { case 0: /* Toggle LED4 */ if (options.elements[TOGGLE_LEDS_IDX].value == 1) STM_EVAL_LEDToggle(LED4); break; case 1: /* Toggle LED3 */ if (options.elements[TOGGLE_LEDS_IDX].value == 1) STM_EVAL_LEDToggle(LED3); break; case 2: break; default: counter = 0; } timeout_0 = TIMEOUT_0_DEFAULT; } if (options.elements[REALTIME_MSG_IDX].value == 1) { enum {WAITFOR_PRESSED, WAITFOR_RELEASED}; static uint8_t what = WAITFOR_PRESSED; char msg[30]; msg[0] = '\0'; if (what == WAITFOR_PRESSED) { if (UserButtonPressed != 0x00) // Interrupt based, don't miss an event //if (STM_EVAL_PBGetState(BUTTON_USER) == 1) { strcpy(msg, "User button pressed"); what = WAITFOR_RELEASED; } } else if (what == WAITFOR_RELEASED) { if (STM_EVAL_PBGetState(BUTTON_USER) == 0) { UserButtonPressed = 0x00; strcpy(msg, "User button released"); what = WAITFOR_PRESSED; } } if (msg[0] != '\0') { #ifndef WIFI_CONNECTED cio_printf("\r\n[info] %s %i\r\n", msg, uptime); #else // send message to each client for(int i=0; i<16; i++) { if(wifi_connections[i].state == CONNECTED) { cio_printf("\x1bS%c[info] %s %i\r\n\x1b""E", wifi_connections[i].cid, msg, uptime); } } #endif } } } }
int main(void) { clock_init(); pin_reserve(PIN_1_1); pin_reserve(PIN_1_2); serial_init(9600); cio_print("** ROCKETuC - librocketcore PIN test **\n\r"); dump_regs("initial"); // invalid port if(pin_setup(0x30, PIN_FUNCTION_OUTPUT) == PIN_STAT_ERR_INVALPORT) { cio_print("0x30 is an invalid port\n\r"); } // invalid pin if(pin_setup(0x2A, PIN_FUNCTION_OUTPUT) == PIN_STAT_ERR_INVALPIN) { cio_print("0x2A is an invalid pin\n\r"); } // P1.1 + P1.2 are reserved for UART1 if(pin_setup(PIN_1_1, PIN_FUNCTION_OUTPUT) == PIN_STAT_ERR_INVALPIN) { cio_print("0x11 is an invalid (reserved) pin\n\r"); } if(pin_setup(PIN_1_2, PIN_FUNCTION_OUTPUT) == PIN_STAT_ERR_INVALPIN) { cio_print("0x12 is an invalid (reserved) pin\n\r"); } // pins on port 2 do not support ADC int p; for(p = 0; p < 8; p++) { if(pin_setup(PIN_2_0 + p, PIN_FUNCTION_ANALOG_IN) == PIN_STAT_ERR_UNSUPFUNC) { cio_printf("0x2%i does not support ADC\n\r", p); } } // set P1.0 + P1.6 + P2.5 to output (the build in LEDs) pin_setup(PIN_1_0, PIN_FUNCTION_OUTPUT); pin_setup(PIN_1_6, PIN_FUNCTION_OUTPUT); pin_setup(PIN_2_5, PIN_FUNCTION_OUTPUT); dump_regs("p1.0+p1.6+p2.5 output"); // set P1.0 + P1.6 + P2.5 to HIGH pin_set(PIN_1_0); pin_set(PIN_1_6); pin_set(PIN_2_5); dump_regs("p1.0+p1.6+p2.5 set"); // read P1.0 + P1.6 + p2.5 states cio_printf("P1.0 is %x\n\r", pin_digital_read(PIN_1_0)); cio_printf("P1.6 is %x\n\r", pin_digital_read(PIN_1_6)); cio_printf("P2.5 is %x\n\r", pin_digital_read(PIN_2_5)); // clear P1.0 + p1.6 + p2.5 to LOW pin_clear(PIN_1_0); pin_clear(PIN_1_6); pin_clear(PIN_2_5); dump_regs("p1.0+p1.6+p2.5 clear"); // read P1.0 + P1.6 + 2.5 states cio_printf("P1.0 is %x\n\r", pin_digital_read(PIN_1_0)); cio_printf("P1.6 is %x\n\r", pin_digital_read(PIN_1_6)); cio_printf("P2.5 is %x\n\r", pin_digital_read(PIN_2_5)); // toggle P1.0 + P1.6 + P2.5 pin_toggle(PIN_1_0); pin_toggle(PIN_1_6); pin_toggle(PIN_2_5); dump_regs("p1.0+p1.6+p2.5 toggle"); // read P1.0 + P1.6 states cio_printf("P1.0 is %x\n\r", pin_digital_read(PIN_1_0)); cio_printf("P1.6 is %x\n\r", pin_digital_read(PIN_1_6)); cio_printf("P2.5 is %x\n\r", pin_digital_read(PIN_2_5)); // toggle P1.0 + P1.6 + P2.5 pin_toggle(PIN_1_0); pin_toggle(PIN_1_6); pin_toggle(PIN_2_5); dump_regs("p1.0+p1.6+p2.5 toggle"); // read P1.0 + P1.6 states cio_printf("P1.0 is %x\n\r", pin_digital_read(PIN_1_0)); cio_printf("P1.6 is %x\n\r", pin_digital_read(PIN_1_6)); cio_printf("P2.5 is %x\n\r", pin_digital_read(PIN_2_5)); // set P1.3 to input float pin_setup(PIN_1_3, PIN_FUNCTION_INPUT_FLOAT); dump_regs("p1.3 input float"); cio_print("Press button on P1.3 to continue ..."); while(pin_digital_read(PIN_1_3)) __asm__("nop"); cio_print(" OK\n\r"); // set P2.3 to input pull-down pin_setup(PIN_2_3, PIN_FUNCTION_INPUT_PULLDOWN); dump_regs("p2.3 input pull-down"); cio_print("Press button on P2.3 to continue ..."); while(!pin_digital_read(PIN_2_3)) __asm__("nop"); cio_print(" OK\n\r"); // set P2.4 to input pull-down pin_setup(PIN_2_4, PIN_FUNCTION_INPUT_PULLUP); dump_regs("p2.4 input pull-up"); cio_print("Press button on P2.4 to continue ..."); while(pin_digital_read(PIN_2_4)) __asm__("nop"); cio_print(" OK\n\r"); int pl = 0; cio_print("Press button on P1.3 for pulselength read ..."); delay(50000); pl = pin_pulselength_read(PIN_1_3); cio_printf(" OK, pl=%i\n\r", pl); cio_print("Press button on P2.3 for pulselength read ..."); delay(50000); pl = pin_pulselength_read(PIN_2_3); cio_printf(" OK, pl=%i\n\r", pl); cio_print("Press button on P2.4 for pulselength read ..."); delay(50000); pl = pin_pulselength_read(PIN_2_4); cio_printf(" OK, pl=%i\n\r", pl); pin_set(PIN_1_0); pin_clear(PIN_1_6); pin_clear(PIN_2_5); // set P1.5 to analog in int i = 0; cio_printf("setup 1.5 for analog in: %i\n\r", pin_setup(PIN_1_5, PIN_FUNCTION_ANALOG_IN)); dump_regs("p1.5 analog in"); int adcin1 = pin_analog_read(PIN_1_5); int adcin2 = 0; cio_printf("Analog read p1.5: %x\n\r", adcin1); // set P2.2 to PWM with period of 20ms and duty cycle of 7.5% cio_printf("setup 2.2 for PWM: %i\n\r", pin_setup(PIN_2_2, PIN_FUNCTION_PWM)); dump_regs("p2.2 PWM"); // only one of the two possible pins on port two are allowed to be set to PWM cio_printf("setup 2.1 for PWM: %i\n\r", pin_setup(PIN_2_1, PIN_FUNCTION_PWM)); // period pin_pwm_function(PIN_2_2, 20000); pin_pwm_control(PIN_2_2, adc2dc(adcin1)); while (1) { delay(); pin_toggle(PIN_1_0); pin_toggle(PIN_1_6); if(i++ % 2 == 0) { pin_toggle(PIN_2_5); } if(!pin_digital_read(PIN_1_3)) { pin_toggle(PIN_1_6); while(!pin_digital_read(PIN_1_3)) __asm__("nop"); } adcin2 = pin_analog_read(PIN_1_5); // only output ADC value if delta was more then 5 if(adcin2 - adcin1 > 5 || adcin1 - adcin2 > 5) { adcin1 = adcin2; cio_printf("Analog read at p1.5: %x (%i)\n\r", adcin2, adcin2); pin_pwm_control(PIN_2_2, adc2dc(adcin1)); } } return 0; }