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
examples/drvdiag/driver_wrapper/ad5270_diag.cpp@7:b62398a1d17a, 2016-04-20 (annotated)
- Committer:
- Adrian Suciu
- Date:
- Wed Apr 20 16:35:44 2016 +0300
- Revision:
- 7:b62398a1d17a
- Child:
- 8:6e96c6b3c83f
Added drvdiag tool
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| Adrian Suciu |
7:b62398a1d17a | 1 | #include "mbed.h" |
| Adrian Suciu |
7:b62398a1d17a | 2 | #include <stdio.h> |
| Adrian Suciu |
7:b62398a1d17a | 3 | #include <vector> |
| Adrian Suciu |
7:b62398a1d17a | 4 | #include <string> |
| Adrian Suciu |
7:b62398a1d17a | 5 | #include "AD5270_Diag.h" |
| Adrian Suciu |
7:b62398a1d17a | 6 | |
| Adrian Suciu |
7:b62398a1d17a | 7 | extern Serial pc; |
| Adrian Suciu |
7:b62398a1d17a | 8 | extern vector<string> cmdbuffer; |
| Adrian Suciu |
7:b62398a1d17a | 9 | |
| Adrian Suciu |
7:b62398a1d17a | 10 | AD5270_Diag::AD5270_Diag(AD5270& ad) : dut(ad) |
| Adrian Suciu |
7:b62398a1d17a | 11 | { |
| Adrian Suciu |
7:b62398a1d17a | 12 | |
| Adrian Suciu |
7:b62398a1d17a | 13 | } |
| Adrian Suciu |
7:b62398a1d17a | 14 | void AD5270_Diag::enable_50TP_programming() |
| Adrian Suciu |
7:b62398a1d17a | 15 | { |
| Adrian Suciu |
7:b62398a1d17a | 16 | dut.enable_50TP_programming(); |
| Adrian Suciu |
7:b62398a1d17a | 17 | pc.printf("Enabled 50TP prog"); |
| Adrian Suciu |
7:b62398a1d17a | 18 | |
| Adrian Suciu |
7:b62398a1d17a | 19 | } |
| Adrian Suciu |
7:b62398a1d17a | 20 | void AD5270_Diag::store_50TP() |
| Adrian Suciu |
7:b62398a1d17a | 21 | { |
| Adrian Suciu |
7:b62398a1d17a | 22 | dut.store_50TP(); |
| Adrian Suciu |
7:b62398a1d17a | 23 | pc.printf("50TP stored"); |
| Adrian Suciu |
7:b62398a1d17a | 24 | } |
| Adrian Suciu |
7:b62398a1d17a | 25 | void AD5270_Diag::disable_50TP_programming() |
| Adrian Suciu |
7:b62398a1d17a | 26 | { |
| Adrian Suciu |
7:b62398a1d17a | 27 | dut.disable_50TP_programming(); |
| Adrian Suciu |
7:b62398a1d17a | 28 | pc.printf("Disabled 50TP prog"); |
| Adrian Suciu |
7:b62398a1d17a | 29 | } |
| Adrian Suciu |
7:b62398a1d17a | 30 | |
| Adrian Suciu |
7:b62398a1d17a | 31 | void AD5270_Diag::write_RDAC() |
| Adrian Suciu |
7:b62398a1d17a | 32 | { |
| Adrian Suciu |
7:b62398a1d17a | 33 | float res = strtof(cmdbuffer[1].c_str(), NULL); |
| Adrian Suciu |
7:b62398a1d17a | 34 | dut.write_RDAC(res); |
| Adrian Suciu |
7:b62398a1d17a | 35 | pc.printf("Wrote %f", res); |
| Adrian Suciu |
7:b62398a1d17a | 36 | } |
| Adrian Suciu |
7:b62398a1d17a | 37 | void AD5270_Diag::read_RDAC() |
| Adrian Suciu |
7:b62398a1d17a | 38 | { |
| Adrian Suciu |
7:b62398a1d17a | 39 | pc.printf("Read %f", dut.read_RDAC()); |
| Adrian Suciu |
7:b62398a1d17a | 40 | } |
| Adrian Suciu |
7:b62398a1d17a | 41 | void AD5270_Diag::write_cmd() |
| Adrian Suciu |
7:b62398a1d17a | 42 | { |
| Adrian Suciu |
7:b62398a1d17a | 43 | uint8_t reg = strtol(cmdbuffer[1].c_str(), NULL, 16); |
| Adrian Suciu |
7:b62398a1d17a | 44 | uint8_t regVal = strtol(cmdbuffer[2].c_str(), NULL, 16); |
| Adrian Suciu |
7:b62398a1d17a | 45 | pc.printf("Returned %x: ", dut.write_cmd(reg, regVal)); |
| Adrian Suciu |
7:b62398a1d17a | 46 | } |
| Adrian Suciu |
7:b62398a1d17a | 47 | |
| Adrian Suciu |
7:b62398a1d17a | 48 | void AD5270_Diag::set_HiZ() |
| Adrian Suciu |
7:b62398a1d17a | 49 | { |
| Adrian Suciu |
7:b62398a1d17a | 50 | pc.printf("SDO set to HiZ"); |
| Adrian Suciu |
7:b62398a1d17a | 51 | dut.set_SDO_HiZ(); |
| Adrian Suciu |
7:b62398a1d17a | 52 | } |
| Adrian Suciu |
7:b62398a1d17a | 53 | |
| Adrian Suciu |
7:b62398a1d17a | 54 | void AD5270_Diag::read_50TP_last_address(void) |
| Adrian Suciu |
7:b62398a1d17a | 55 | { |
| Adrian Suciu |
7:b62398a1d17a | 56 | pc.printf("Returned %x:", dut.read_50TP_last_address()); |
| Adrian Suciu |
7:b62398a1d17a | 57 | } |
| Adrian Suciu |
7:b62398a1d17a | 58 | void AD5270_Diag::read_50TP_memory(void) |
| Adrian Suciu |
7:b62398a1d17a | 59 | { |
| Adrian Suciu |
7:b62398a1d17a | 60 | uint8_t reg = strtol(cmdbuffer[1].c_str(), NULL, 16); |
| Adrian Suciu |
7:b62398a1d17a | 61 | pc.printf("Returned %x", dut.read_50TP_memory(reg)); |
| Adrian Suciu |
7:b62398a1d17a | 62 | } |
| Adrian Suciu |
7:b62398a1d17a | 63 | |
| Adrian Suciu |
7:b62398a1d17a | 64 | void AD5270_Diag::write_ctrl_reg(void) |
| Adrian Suciu |
7:b62398a1d17a | 65 | { |
| Adrian Suciu |
7:b62398a1d17a | 66 | uint8_t val = strtol(cmdbuffer[1].c_str(), NULL, 16); |
| Adrian Suciu |
7:b62398a1d17a | 67 | dut.write_ctrl_reg(val); |
| Adrian Suciu |
7:b62398a1d17a | 68 | pc.printf("Wrote %x to ctrl_reg", val ); |
| Adrian Suciu |
7:b62398a1d17a | 69 | } |
| Adrian Suciu |
7:b62398a1d17a | 70 | void AD5270_Diag::read_ctrl_reg(void) |
| Adrian Suciu |
7:b62398a1d17a | 71 | { |
| Adrian Suciu |
7:b62398a1d17a | 72 | pc.printf("Read %x from ctrl_reg", dut.read_ctrl_reg()); |
| Adrian Suciu |
7:b62398a1d17a | 73 | } |
| Adrian Suciu |
7:b62398a1d17a | 74 | |
| Adrian Suciu |
7:b62398a1d17a | 75 | void AD5270_Diag::reset_RDAC(void) |
| Adrian Suciu |
7:b62398a1d17a | 76 | { |
| Adrian Suciu |
7:b62398a1d17a | 77 | dut.reset_RDAC(); |
| Adrian Suciu |
7:b62398a1d17a | 78 | pc.printf("Resetted rdac"); |
| Adrian Suciu |
7:b62398a1d17a | 79 | } |
| Adrian Suciu |
7:b62398a1d17a | 80 | void AD5270_Diag::change_mode(void) |
| Adrian Suciu |
7:b62398a1d17a | 81 | { |
| Adrian Suciu |
7:b62398a1d17a | 82 | uint8_t val = strtol(cmdbuffer[1].c_str(), NULL, 16); |
| Adrian Suciu |
7:b62398a1d17a | 83 | dut.change_mode(static_cast<AD5270::AD5270Modes_t>(val)); |
| Adrian Suciu |
7:b62398a1d17a | 84 | pc.printf("Changed mode to %x", val); |
| Adrian Suciu |
7:b62398a1d17a | 85 | } |
| Adrian Suciu |
7:b62398a1d17a | 86 | |
| Adrian Suciu |
7:b62398a1d17a | 87 | void AD5270_Diag::write_wiper_reg(void) |
| Adrian Suciu |
7:b62398a1d17a | 88 | { |
| Adrian Suciu |
7:b62398a1d17a | 89 | uint16_t val = strtol(cmdbuffer[1].c_str(), NULL, 16); |
| Adrian Suciu |
7:b62398a1d17a | 90 | dut.write_wiper_reg(val); |
| Adrian Suciu |
7:b62398a1d17a | 91 | pc.printf("Wrote %x to wiper", val); |
| Adrian Suciu |
7:b62398a1d17a | 92 | } |
| Adrian Suciu |
7:b62398a1d17a | 93 | void AD5270_Diag::read_wiper_reg(void) |
| Adrian Suciu |
7:b62398a1d17a | 94 | { |
| Adrian Suciu |
7:b62398a1d17a | 95 | pc.printf("Read %x from wiper", dut.read_wiper_reg()); |
| Adrian Suciu |
7:b62398a1d17a | 96 | } |
CN0357 - Toxic gas measurement
CN0216 - Weight Scale