void adc_enable_single_swstart(adc_dev *dev) { adc_init(dev); adc_set_extsel(dev, ADC_SWSTART); adc_set_exttrig(dev, 1); adc_enable(dev); adc_calibrate(dev); }
void cmd_readadc(char *line) { adc_init(PIN_MAP[12].adc_device); // all on ADC1 adc_set_extsel(PIN_MAP[12].adc_device, ADC_SWSTART); adc_set_exttrig(PIN_MAP[12].adc_device, true); adc_enable(PIN_MAP[12].adc_device); adc_calibrate(PIN_MAP[12].adc_device); adc_set_sample_rate(PIN_MAP[12].adc_device, ADC_SMPR_55_5); gpio_set_mode (PIN_MAP[12].gpio_device,PIN_MAP[12].gpio_bit, GPIO_INPUT_ANALOG); gpio_set_mode (PIN_MAP[19].gpio_device,PIN_MAP[19].gpio_bit, GPIO_INPUT_ANALOG); gpio_set_mode (PIN_MAP[20].gpio_device,PIN_MAP[20].gpio_bit, GPIO_INPUT_ANALOG); uint16 value1 = adc_read(PIN_MAP[12].adc_device,PIN_MAP[12].adc_channel); uint16 value2 = adc_read(PIN_MAP[19].adc_device,PIN_MAP[19].adc_channel); uint16 value3 = adc_read(PIN_MAP[20].adc_device,PIN_MAP[20].adc_channel); char values[50]; sprintf(values,"PA6 ADC Read: %u\r\n",value1); serial_write_string(values); sprintf(values,"PC4 ADC Read: %u\r\n",value2); serial_write_string(values); sprintf(values,"PC5 ADC Read: %u\r\n",value3); serial_write_string(values); }
static void adcDefaultConfig(const adc_dev* dev) { adc_init(dev); adc_set_extsel(dev, ADC_SWSTART); adc_set_exttrig(dev, 1); adc_enable(dev); adc_calibrate(dev); adc_set_sample_rate(dev, ADC_SMPR_55_5); }
static void adcDefaultConfig(const adc_dev *dev) { adc_init(dev); // ok adc_set_extsel(dev, ADC_SWSTART); // ok adc_set_exttrig(dev, true); // ok adc_enable(dev); // up to 1mA adc_calibrate(dev); // stick at 1mA adc_set_sample_rate(dev, ADC_SMPR_55_5); // stick at 1mA }
void serial_process_command(char *line) { if(in_displayparams) { serial_displayparams_run(line); in_displayparams = false; } if(in_setdevicetag) { serial_setdevicetag_run(line); in_setdevicetag = false; } if(in_setrtc) { serial_setrtc_run(line); in_setrtc = false; } if(in_setkeyval) { serial_setkeyval_run(line); in_setkeyval = false; } serial_write_string("\r\n"); if(strcmp(line,"HELLO") == 0) { serial_write_string("GREETINGS PROFESSOR FALKEN.\r\n"); } else if(strcmp(line,"LIST GAMES") == 0) { serial_write_string("I'M KIND OF BORED OF GAMES, TURNS OUT THE ONLY WAY TO WIN IS NOT TO PLAY...\r\n"); } else if(strcmp(line,"LOGXFER") == 0) { serial_sendlog(); } else if(strcmp(line,"DISPLAYPARAMS") == 0) { serial_displayparams(); } else if(strcmp(line,"HELP") == 0) { serial_write_string("Available commands: HELP, LOGXFER, DISPLAYTEST, HELLO"); } else if(strcmp(line,"DISPLAYTEST") == 0) { display_test(); } else if(strcmp(line,"LOGTEST") == 0) { char stemp[100]; sprintf(stemp,"Raw log data\r\n"); serial_write_string(stemp); uint8_t *flash_log = flashstorage_log_get(); for(int n=0;n<1024;n++) { sprintf(stemp,"%u ",flash_log[n]); serial_write_string(stemp); if(n%64 == 0) serial_write_string("\r\n"); } serial_write_string("\r\n"); log_data_t data; data.time = 0; data.cpm = 1; data.accel_x_start = 2; data.accel_y_start = 3; data.accel_z_start = 4; data.accel_x_end = 5; data.accel_y_end = 6; data.accel_z_end = 7; data.log_type = UINT_MAX; sprintf(stemp,"Log size: %u\r\n",flashstorage_log_size()); serial_write_string(stemp); sprintf(stemp,"Writing test log entry of size: %u\r\n",sizeof(log_data_t)); serial_write_string(stemp); flashstorage_log_pushback((uint8 *) &data,sizeof(log_data_t)); sprintf(stemp,"Log size: %u\r\n",flashstorage_log_size()); serial_write_string(stemp); } else if(strcmp(line,"VERSION") == 0) { char stemp[50]; sprintf(stemp,"Version: %s\r\n",OS100VERSION); serial_write_string(stemp); } else if(strcmp(line,"GETDEVICETAG") == 0) { const char *devicetag = flashstorage_keyval_get("DEVICETAG"); if(devicetag != 0) { char stemp[100]; sprintf(stemp,"Devicetag: %s\r\n",devicetag); serial_write_string(stemp); } else { serial_write_string("No device tag set"); } } else if(strcmp(line,"SETDEVICETAG") == 0) { serial_setdevicetag(); } else if(strcmp(line,"READPRIVATEKEY") == 0) { // serial_readprivatekey(); // removed for production } else if(strcmp(line,"WRITEPRIVATEKEY") == 0) { // serial_writeprivatekey(); // maybe this should be removed for production? } else if(strcmp(line,"MAGREAD") == 0) { gpio_set_mode (PIN_MAP[41].gpio_device,PIN_MAP[41].gpio_bit, GPIO_OUTPUT_PP); // MAGPOWER gpio_set_mode (PIN_MAP[29].gpio_device,PIN_MAP[29].gpio_bit, GPIO_INPUT_PU); // MAGSENSE // Power up magsense gpio_write_bit(PIN_MAP[41].gpio_device,PIN_MAP[41].gpio_bit,1); // wait... delay_us(1000); // Read magsense int magsense = gpio_read_bit(PIN_MAP[29].gpio_device,PIN_MAP[29].gpio_bit); char magsenses[50]; sprintf(magsenses,"%u\r\n",magsense); serial_write_string(magsenses); } else if(strcmp(line,"WRITEDAC") == 0) { dac_init(DAC,DAC_CH2); int8_t idelta=1; uint8_t i=0; for(int n=0;n<1000000;n++) { if(i == 254) idelta = -1; if(i == 0 ) idelta = 1; i += idelta; dac_write_channel(DAC,2,i); } serial_write_string("WRITEDACFIN"); } else if(strcmp(line,"TESTHP") == 0) { gpio_set_mode (PIN_MAP[12].gpio_device,PIN_MAP[12].gpio_bit, GPIO_OUTPUT_PP); // HP_COMBINED for(int n=0;n<100000;n++) { gpio_write_bit(PIN_MAP[12].gpio_device,PIN_MAP[12].gpio_bit,1); delay_us(100); gpio_write_bit(PIN_MAP[12].gpio_device,PIN_MAP[12].gpio_bit,0); delay_us(100); } } else if(strcmp(line,"READADC") == 0) { adc_init(PIN_MAP[12].adc_device); // all on ADC1 adc_set_extsel(PIN_MAP[12].adc_device, ADC_SWSTART); adc_set_exttrig(PIN_MAP[12].adc_device, true); adc_enable(PIN_MAP[12].adc_device); adc_calibrate(PIN_MAP[12].adc_device); adc_set_sample_rate(PIN_MAP[12].adc_device, ADC_SMPR_55_5); gpio_set_mode (PIN_MAP[12].gpio_device,PIN_MAP[12].gpio_bit, GPIO_INPUT_ANALOG); gpio_set_mode (PIN_MAP[19].gpio_device,PIN_MAP[19].gpio_bit, GPIO_INPUT_ANALOG); gpio_set_mode (PIN_MAP[20].gpio_device,PIN_MAP[20].gpio_bit, GPIO_INPUT_ANALOG); int n=0; uint16 value1 = adc_read(PIN_MAP[12].adc_device,PIN_MAP[12].adc_channel); uint16 value2 = adc_read(PIN_MAP[19].adc_device,PIN_MAP[19].adc_channel); uint16 value3 = adc_read(PIN_MAP[20].adc_device,PIN_MAP[20].adc_channel); char values[50]; sprintf(values,"PA6 ADC Read: %u\r\n",value1); serial_write_string(values); sprintf(values,"PC4 ADC Read: %u\r\n",value2); serial_write_string(values); sprintf(values,"PC5 ADC Read: %u\r\n",value3); serial_write_string(values); } else if(strcmp(line,"SETMICREVERSE") == 0) { gpio_set_mode (PIN_MAP[36].gpio_device,PIN_MAP[36].gpio_bit, GPIO_OUTPUT_PP); // MICREVERSE gpio_set_mode (PIN_MAP[35].gpio_device,PIN_MAP[35].gpio_bit, GPIO_OUTPUT_PP); // MICIPHONE gpio_write_bit(PIN_MAP[36].gpio_device,PIN_MAP[36].gpio_bit,1); // MICREVERSE gpio_write_bit(PIN_MAP[35].gpio_device,PIN_MAP[35].gpio_bit,0); // MICIPHONE serial_write_string("Set MICREVERSE to 1, MICIPHONE to 0\r\n"); } else if(strcmp(line,"SETMICIPHONE") == 0) { gpio_set_mode (PIN_MAP[36].gpio_device,PIN_MAP[36].gpio_bit, GPIO_OUTPUT_PP); // MICREVERSE gpio_set_mode (PIN_MAP[35].gpio_device,PIN_MAP[35].gpio_bit, GPIO_OUTPUT_PP); // MICIPHONE gpio_write_bit(PIN_MAP[36].gpio_device,PIN_MAP[36].gpio_bit,0); // MICREVERSE gpio_write_bit(PIN_MAP[35].gpio_device,PIN_MAP[35].gpio_bit,1); // MICIPHONE serial_write_string("Set MICREVERSE to 0, MICIPHONE to 1\r\n"); } else if(strcmp(line,"TESTSIGN") == 0) { serial_signing_test(); } else if(strcmp(line,"PUBKEY") == 0) { signing_printPubKey(); serial_write_string("\n\r"); } else if(strcmp(line,"GUID") == 0) { signing_printGUID(); serial_write_string("\n\r"); } else if(strcmp(line,"KEYVALID") == 0) { if( signing_isKeyValid() == 1 ) serial_write_string("uu_valid VALID KEY\r\n"); else serial_write_string("uu_valid IMPROPER OR UNINITIALIZED KEY\r\n"); } else if(strcmp(line,"LOGSIG") == 0) { signing_hashLog(); serial_write_string("\n\r"); } else if(strcmp(line,"LOGPAUSE") == 0) { flashstorage_log_pause(); } else if(strcmp(line,"LOGRESUME") == 0) { flashstorage_log_resume(); } else if(strcmp(line,"LOGCLEAR") == 0) { serial_write_string("Clearing flash log\r\n"); flashstorage_log_clear(); serial_write_string("Cleared\r\n"); } else if(strcmp(line,"KEYVALDUMP") == 0) { serial_keyvaldump(); } else if(strcmp(line,"KEYVALSET") == 0) { serial_setkeyval(); } else if(strcmp(line,"SETRTC") == 0) { serial_setrtc(); } else if(strcmp(line,"RTCALARM") == 0) { serial_write_string("Alarm triggered for 10s\r\n"); rtc_set_alarm(RTC,rtc_get_time(RTC)+10); } serial_write_string("\r\n>"); }