A collection of Analog Devices drivers for the mbed platform
For additional information check out the mbed page of the Analog Devices wiki: https://wiki.analog.com/resources/tools-software/mbed-drivers-all
Diff: examples/drvdiag/main.cpp
- Revision:
- 26:1b988c505139
- Parent:
- 21:a8023e5e97be
--- a/examples/drvdiag/main.cpp Wed May 18 16:57:57 2016 +0300 +++ b/examples/drvdiag/main.cpp Thu Aug 18 14:46:42 2016 +0300 @@ -53,6 +53,7 @@ #include "config.h" Serial pc(SERIAL_TX, SERIAL_RX); +Serial test(D8, D2); vector<string> cmdbuffer; class commands @@ -65,11 +66,13 @@ void (*fktPtr)(void); }; + // *INDENT-OFF* const vector<commands> cmdlist = { {"nop" , 0, [](){ }}, + /* {"echo",commands::VAR, [](){ for(auto i = begin(cmdbuffer) + 1, e = end(cmdbuffer); i!=e; ++i) - printf("%s ", i->c_str()); printf("\r\n");}}, + printf("%s ", i->c_str()); printf("\r\n");}},*/ {"help", 0 , [](){ for(auto command : cmdlist) pc.printf("%s ",command.cmd_str.c_str()); }}, @@ -159,12 +162,125 @@ {"xlfr16", 0, [](){adxl362diag.fifo_read_u16(); }}, {"xlfrs", 0, [](){adxl362diag.fifo_scan(); }}, {"xlintinit",0,[](){adxl362diag.intinit();}}, - {"xlawake",0,[](){adxl362diag.checkawake();} - }, + {"xlawake",0,[](){adxl362diag.checkawake();}}, +#endif + + +// UART + {"uart" , 0, [](){test.putc('\n');}}, + {"uartecho" , 1, [](){test.printf(cmdbuffer[1].c_str());}}, + {"uartlisten",0 , [](){ + char buff[100] = {0}; + size_t readPosition = 0; + + // read from console until newline + while(1) { + buff[readPosition] = test.getc(); + if(buff[readPosition] == '\n' || buff[readPosition] == '\r') { + buff[readPosition] = ' '; + break; + } + readPosition++; + } + readPosition++; + buff[readPosition] = '\0'; + //create std::string from char buffer + + pc.printf("%s",buff);}}, + +#ifdef AD7124_PRESENT + {"adrst" , 0, [](){ad7124diag.reset();}}, + {"adrd" , 1, [](){ad7124diag.read_reg();}}, + {"adrdd" , 0, [](){ad7124diag.read_data();}}, + {"adrdv" , 0, [](){ad7124diag.read_volt();}}, + {"adwr" , 2, [](){ad7124diag.write_reg();}}, + {"adsetup",0,[]() {ad7124diag.setup();pc.printf("setup done\r\n");ad7124diag.mvpInit();pc.printf("init done\r\n");}} + + + +#endif + +#ifdef CN0398_PRESENT + {"cnrst" , 0, [](){cn0398diag.reset();}}, + {"cnrd" , 1, [](){cn0398diag.read_reg();}}, + /*{"cnrdd" , 0, [](){ad7124diag.read_data();}}, + {"cnrdv" , 0, [](){ad7124diag.read_volt();}},*/ + {"cnwr" , 2, [](){cn0398diag.write_reg();}}, + {"cnsetup",0,[]() {cn0398diag.init();pc.printf("init done\r\n");}}, + {"cnled0",1,[]() {cn0398diag.toggle_output(1,strtol(cmdbuffer[1].c_str(), NULL, 16)); pc.printf("LED1 toggled"); }}, + {"cnled1",1,[]() {cn0398diag.toggle_output(2,strtol(cmdbuffer[1].c_str(), NULL, 16));pc.printf("LED2 toggled");}}, + {"cnoffp",0,[]() {cn0398diag.offsetph();pc.printf("OffsetVoltage measured");}}, + {"cnpcal0",1,[]() {cn0398diag.calibp(0);pc.printf("calibration point 0");}}, + {"cnpcal1",1,[]() {cn0398diag.calibp(1);pc.printf("calibration point 1");}}, + {"cnreadp",0,[]() {cn0398diag.readp();pc.printf("calibration point 1");}}, + {"cnreadm",0,[]() {cn0398diag.readm();pc.printf("calibration point 1");}}, + {"cnreadt",0,[]() {cn0398diag.readt();pc.printf("Temperature Read");}}, + + #endif +#ifdef CN0397_PRESENT + {"cnrst" , 0, [](){cn0397diag.reset();}}, + /* {"cnrd" , 1, [](){cn0397diag.read_reg();}}, + {"cnwr" , 2, [](){cn0397diag.write_reg();}},*/ + {"cnsetup",0,[]() {cn0397diag.init();pc.printf("init done\r\n");}}, + {"cnread",0,[]() {cn0397diag.read();pc.printf("calibration point 1");}}, +#endif + +#ifdef CN0396_PRESENT + {"cntrst" , 0, [](){pc.printf("reset temp sensor \r\n");cn0396diag.dut.temp.reset();}}, + {"cntrds" , 0, [](){pc.printf("temp status: %x \r\n",cn0396diag.dut.temp.read_status());}}, + {"cntrdt" , 0, [](){pc.printf("temp val: %x \r\n",cn0396diag.dut.temp.read_temp());}}, + {"cntrdc" , 0, [](){pc.printf("temp val: %x \r\n",cn0396diag.dut.temp.read_config());}}, + {"cntwcf" , 1, [](){pc.printf("wrote config: %x \r\n",strtol(cmdbuffer[1].c_str(), NULL, 16)); + cn0396diag.dut.temp.write_config(strtol(cmdbuffer[1].c_str(), NULL, 16));}}, + {"cnardi" , 0, [](){pc.printf("adid : %x \r\n",cn0396diag.dut.ad.get_register_value(3,1,true));}}, + + {"rdwrr" , 1, [](){ad5270diag.write_RDAC();}}, + {"rdrdr" , 0, [](){ad5270diag.read_RDAC();}}, + {"rdwrcmd" , 2, [](){ad5270diag.write_cmd();}}, + {"rdsetz" , 0, [](){ad5270diag.set_HiZ();}}, + {"rd50en", 0, [](){ad5270diag.enable_50TP_programming();}}, + {"rd50ds", 0, [](){ad5270diag.disable_50TP_programming();}}, + {"rd50st", 0, [](){ad5270diag.store_50TP();}}, + {"rd50a" , 0, [](){ad5270diag.read_50TP_last_address();}}, + {"rd50m" , 1, [](){ad5270diag.read_50TP_memory();}}, + {"rdwrc" , 1, [](){ad5270diag.write_ctrl_reg();}}, + {"rdrdc" , 0, [](){ad5270diag.read_ctrl_reg();}}, + {"rdrst" , 0, [](){ad5270diag.reset_RDAC();}}, + {"rdchm" , 1, [](){ad5270diag.change_mode();}}, + {"rdwrw" , 1, [](){ad5270diag.write_wiper_reg();}}, + {"rdrdw" , 0, [](){ad5270diag.read_wiper_reg();}}, + {"rddc" , 0, [](){ uint8_t daisy[4]={0x08,0x00,0x08,0x00}; + ad5270diag.dut.daisy_chain(daisy,4); + for(uint8_t i=0;i<4;i++) + { + pc.printf("%x ",daisy[i]); + } + pc.printf("\r\n"); + } + }, + {"trdid",0,[](){uint8_t val = cn0396diag.dut.temp.read_id(); + pc.printf("%x \r\n",val);}}, + {"ardid",0,[](){uint8_t val = cn0396diag.dut.ad.get_register_value(AD7798_REG_ID,1); + pc.printf("%x \r\n",val);}}, + {"adrst",0,[](){cn0396diag.dut.ad.reset();pc.printf("reseted ADC \r\n");}}, + {"cnrst",0,[](){ + uint8_t daisy1[4]={0x08,0x01,0x08,0x01}; + cn0396diag.dut.rdac.daisy_chain(daisy1,4); + uint8_t daisy2[4]={0,0,0,0}; + cn0396diag.dut.rdac.daisy_chain(daisy2,4); + cn0396diag.dut.ad.reset(); + cn0396diag.dut.temp.reset(); + pc.printf("reseted ADC \r\n"); + }}, + + + + +#endif }; // *INDENT-ON* @@ -223,8 +339,17 @@ int main() { + pc.baud(115200); + test.baud(76800); // ad7791.frequency(100000); pc.printf("\r\n#### DrvDiag ####\r\n"); + cn0396.ad.frequency(500000); + cn0396.rdac.frequency(500000); + cn0396.temp.frequency(500000); + + cn0396.csad = true; + cn0396.csrdac = true; + cn0396.cstemp = true; while(1) { pc.printf("\r\nTX> ");