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/ad7790_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 "AD7790_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 | AD7790_Diag::AD7790_Diag(AD7790& ad) : dut(ad) |
| Adrian Suciu |
7:b62398a1d17a | 11 | { |
| Adrian Suciu |
7:b62398a1d17a | 12 | |
| Adrian Suciu |
7:b62398a1d17a | 13 | } |
| Adrian Suciu |
7:b62398a1d17a | 14 | |
| Adrian Suciu |
7:b62398a1d17a | 15 | void AD7790_Diag::init() |
| Adrian Suciu |
7:b62398a1d17a | 16 | { |
| Adrian Suciu |
7:b62398a1d17a | 17 | |
| Adrian Suciu |
7:b62398a1d17a | 18 | } |
| Adrian Suciu |
7:b62398a1d17a | 19 | void AD7790_Diag::reset() |
| Adrian Suciu |
7:b62398a1d17a | 20 | { |
| Adrian Suciu |
7:b62398a1d17a | 21 | dut.reset(); |
| Adrian Suciu |
7:b62398a1d17a | 22 | pc.printf("Reseted AD7790"); |
| Adrian Suciu |
7:b62398a1d17a | 23 | } |
| Adrian Suciu |
7:b62398a1d17a | 24 | |
| Adrian Suciu |
7:b62398a1d17a | 25 | void AD7790_Diag::write_mode() |
| Adrian Suciu |
7:b62398a1d17a | 26 | { |
| Adrian Suciu |
7:b62398a1d17a | 27 | uint8_t regVal = strtol(cmdbuffer[1].c_str(), NULL, 16); |
| Adrian Suciu |
7:b62398a1d17a | 28 | dut.write_mode_reg(regVal); |
| Adrian Suciu |
7:b62398a1d17a | 29 | pc.printf("Wrote mode"); |
| Adrian Suciu |
7:b62398a1d17a | 30 | } |
| Adrian Suciu |
7:b62398a1d17a | 31 | void AD7790_Diag::read_mode() |
| Adrian Suciu |
7:b62398a1d17a | 32 | { |
| Adrian Suciu |
7:b62398a1d17a | 33 | pc.printf("Mode reg: %x ", dut.read_mode_reg()); |
| Adrian Suciu |
7:b62398a1d17a | 34 | } |
| Adrian Suciu |
7:b62398a1d17a | 35 | |
| Adrian Suciu |
7:b62398a1d17a | 36 | void AD7790_Diag::write_filter() |
| Adrian Suciu |
7:b62398a1d17a | 37 | { |
| Adrian Suciu |
7:b62398a1d17a | 38 | uint8_t regVal = strtol(cmdbuffer[1].c_str(), NULL, 16); |
| Adrian Suciu |
7:b62398a1d17a | 39 | dut.write_filter_reg(regVal); |
| Adrian Suciu |
7:b62398a1d17a | 40 | pc.printf("Wrote filter"); |
| Adrian Suciu |
7:b62398a1d17a | 41 | } |
| Adrian Suciu |
7:b62398a1d17a | 42 | void AD7790_Diag::read_filter() |
| Adrian Suciu |
7:b62398a1d17a | 43 | { |
| Adrian Suciu |
7:b62398a1d17a | 44 | pc.printf("Returned: %x ", dut.read_filter_reg()); |
| Adrian Suciu |
7:b62398a1d17a | 45 | } |
| Adrian Suciu |
7:b62398a1d17a | 46 | void AD7790_Diag::read_data() |
| Adrian Suciu |
7:b62398a1d17a | 47 | { |
| Adrian Suciu |
7:b62398a1d17a | 48 | pc.printf("Data reg: %x ", dut.read_data_reg()); |
| Adrian Suciu |
7:b62398a1d17a | 49 | } |
| Adrian Suciu |
7:b62398a1d17a | 50 | |
| Adrian Suciu |
7:b62398a1d17a | 51 | void AD7790_Diag::read_status() |
| Adrian Suciu |
7:b62398a1d17a | 52 | { |
| Adrian Suciu |
7:b62398a1d17a | 53 | pc.printf("Status reg: %x ", dut.read_status_reg()); |
| Adrian Suciu |
7:b62398a1d17a | 54 | } |
| Adrian Suciu |
7:b62398a1d17a | 55 | |
| Adrian Suciu |
7:b62398a1d17a | 56 | void AD7790_Diag::read_u16() |
| Adrian Suciu |
7:b62398a1d17a | 57 | { |
| Adrian Suciu |
7:b62398a1d17a | 58 | pc.printf("Data reg: %x ", dut.read_u16()); |
| Adrian Suciu |
7:b62398a1d17a | 59 | } |
| Adrian Suciu |
7:b62398a1d17a | 60 | void AD7790_Diag::read_voltage() |
| Adrian Suciu |
7:b62398a1d17a | 61 | { |
| Adrian Suciu |
7:b62398a1d17a | 62 | pc.printf("Voltage: %f ", dut.read_voltage()); |
| Adrian Suciu |
7:b62398a1d17a | 63 | } |
| Adrian Suciu |
7:b62398a1d17a | 64 | void AD7790_Diag::set_continous_mode() |
| Adrian Suciu |
7:b62398a1d17a | 65 | { |
| Adrian Suciu |
7:b62398a1d17a | 66 | uint8_t regVal = strtol(cmdbuffer[1].c_str(), NULL, 16); |
| Adrian Suciu |
7:b62398a1d17a | 67 | dut.set_conversion_mode(static_cast<AD7790::AD7790Mode_t>(regVal)); |
| Adrian Suciu |
7:b62398a1d17a | 68 | pc.printf("Mode set to %d", regVal); |
| Adrian Suciu |
7:b62398a1d17a | 69 | } |
| Adrian Suciu |
7:b62398a1d17a | 70 | void AD7790_Diag::set_reference_voltage() |
| Adrian Suciu |
7:b62398a1d17a | 71 | { |
| Adrian Suciu |
7:b62398a1d17a | 72 | float ref = strtof(cmdbuffer[1].c_str(), NULL); |
| Adrian Suciu |
7:b62398a1d17a | 73 | dut.set_reference_voltage(ref); |
| Adrian Suciu |
7:b62398a1d17a | 74 | pc.printf("Reference Voltage set to %f", ref); |
| Adrian Suciu |
7:b62398a1d17a | 75 | } |
| Adrian Suciu |
7:b62398a1d17a | 76 | |
| Adrian Suciu |
7:b62398a1d17a | 77 | void AD7790_Diag::set_channel() |
| Adrian Suciu |
7:b62398a1d17a | 78 | { |
| Adrian Suciu |
7:b62398a1d17a | 79 | uint8_t regVal = strtol(cmdbuffer[1].c_str(), NULL, 16); |
| Adrian Suciu |
7:b62398a1d17a | 80 | dut.set_channel(static_cast<AD7790::AD7790Channel_t>(regVal)); |
| Adrian Suciu |
7:b62398a1d17a | 81 | pc.printf("Mode set to %d", regVal); |
| Adrian Suciu |
7:b62398a1d17a | 82 | } |
CN0357 - Toxic gas measurement
CN0216 - Weight Scale