aboutsummaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorMarti Bolivar <mbolivar@leaflabs.com>2012-06-22 14:47:45 -0400
committerMarti Bolivar <mbolivar@leaflabs.com>2012-06-22 15:07:08 -0400
commite397f7c18b775aacf40223a7cc91cba547e819e7 (patch)
treec77d1ed02153b699b60eeef0d500ec397bab07e4 /examples
parentf94c9f659be11340b80476cec8c0f713e4bba02c (diff)
downloadlibrambutan-e397f7c18b775aacf40223a7cc91cba547e819e7.tar.gz
librambutan-e397f7c18b775aacf40223a7cc91cba547e819e7.zip
i2c-mcp4725-dac.cpp: Fix whitespace.
Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
Diffstat (limited to 'examples')
-rw-r--r--examples/i2c-mcp4725-dac.cpp118
1 files changed, 59 insertions, 59 deletions
diff --git a/examples/i2c-mcp4725-dac.cpp b/examples/i2c-mcp4725-dac.cpp
index e757bd1..da9a34e 100644
--- a/examples/i2c-mcp4725-dac.cpp
+++ b/examples/i2c-mcp4725-dac.cpp
@@ -41,66 +41,66 @@ static i2c_msg read_msg;
*/
void mcp_i2c_setup(void) {
- write_msg.addr = MCP_ADDR;
- write_msg.flags = 0; // write, 7 bit address
- write_msg.length = sizeof(write_msg_data);
- write_msg.xferred = 0;
- write_msg.data = write_msg_data;
-
- read_msg.addr = MCP_ADDR;
- read_msg.flags = I2C_MSG_READ;
- read_msg.length = sizeof(read_msg_data);
- read_msg.xferred = 0;
- read_msg.data = read_msg_data;
+ write_msg.addr = MCP_ADDR;
+ write_msg.flags = 0; // write, 7 bit address
+ write_msg.length = sizeof(write_msg_data);
+ write_msg.xferred = 0;
+ write_msg.data = write_msg_data;
+
+ read_msg.addr = MCP_ADDR;
+ read_msg.flags = I2C_MSG_READ;
+ read_msg.length = sizeof(read_msg_data);
+ read_msg.xferred = 0;
+ read_msg.data = read_msg_data;
}
void mcp_write_val(uint16 val) {
- write_msg_data[0] = MCP_WRITE_DAC | MCP_PD_NORMAL;
- uint16 tmp = val >> 4;
- write_msg_data[1] = tmp;
- tmp = (val << 4) & 0x00FF;
- write_msg_data[2] = tmp;
+ write_msg_data[0] = MCP_WRITE_DAC | MCP_PD_NORMAL;
+ uint16 tmp = val >> 4;
+ write_msg_data[1] = tmp;
+ tmp = (val << 4) & 0x00FF;
+ write_msg_data[2] = tmp;
- i2c_master_xfer(I2C2, &write_msg, 1, 0);
+ i2c_master_xfer(I2C2, &write_msg, 1, 0);
}
uint16 mcp_read_val() {
- uint16 tmp = 0;
+ uint16 tmp = 0;
- i2c_master_xfer(I2C2, &read_msg, 1, 2);
+ i2c_master_xfer(I2C2, &read_msg, 1, 2);
- /* We don't care about the status and EEPROM bytes (0, 3, and 4). */
- tmp = (read_msg_data[1] << 4);
- tmp += (read_msg_data[2] >> 4);
- return tmp;
+ /* We don't care about the status and EEPROM bytes (0, 3, and 4). */
+ tmp = (read_msg_data[1] << 4);
+ tmp += (read_msg_data[2] >> 4);
+ return tmp;
}
int mcp_test() {
- uint16 val;
- uint16 test_val = 0x0101;
-
- SerialUSB.println("Testing the MCP4725...");
- /* Read the value of the register (should be 0x0800 if factory fresh) */
- val = mcp_read_val();
- SerialUSB.print("DAC Register = 0x");
- SerialUSB.println(val, HEX);
-
- mcp_write_val(test_val);
- SerialUSB.print("Wrote 0x");
- SerialUSB.print(test_val, HEX);
- SerialUSB.println(" to the DAC");
-
- val = mcp_read_val();
- SerialUSB.print("DAC Register = 0x");
- SerialUSB.println(val, HEX);
-
- if (val != test_val) {
- SerialUSB.println("ERROR: MCP4725 not responding correctly");
- return 0;
- }
+ uint16 val;
+ uint16 test_val = 0x0101;
+
+ SerialUSB.println("Testing the MCP4725...");
+ /* Read the value of the register (should be 0x0800 if factory fresh) */
+ val = mcp_read_val();
+ SerialUSB.print("DAC Register = 0x");
+ SerialUSB.println(val, HEX);
+
+ mcp_write_val(test_val);
+ SerialUSB.print("Wrote 0x");
+ SerialUSB.print(test_val, HEX);
+ SerialUSB.println(" to the DAC");
+
+ val = mcp_read_val();
+ SerialUSB.print("DAC Register = 0x");
+ SerialUSB.println(val, HEX);
+
+ if (val != test_val) {
+ SerialUSB.println("ERROR: MCP4725 not responding correctly");
+ return 0;
+ }
- SerialUSB.println("MCP4725 seems to be working");
- return 1;
+ SerialUSB.println("MCP4725 seems to be working");
+ return 1;
}
/*
@@ -108,25 +108,25 @@ int mcp_test() {
*/
void setup() {
- pinMode(BOARD_BUTTON_PIN, INPUT);
- i2c_master_enable(I2C2, 0);
- mcp_i2c_setup();
+ pinMode(BOARD_BUTTON_PIN, INPUT);
+ i2c_master_enable(I2C2, 0);
+ mcp_i2c_setup();
- waitForButtonPress();
- ASSERT(mcp_test());
+ waitForButtonPress();
+ ASSERT(mcp_test());
- SerialUSB.println("Starting sawtooth wave");
+ SerialUSB.println("Starting sawtooth wave");
}
void loop() {
- static uint16 dout = 0;
+ static uint16 dout = 0;
- mcp_write_val(dout);
+ mcp_write_val(dout);
- dout += 50;
- if (dout >= 32768) {
- dout = 0;
- }
+ dout += 50;
+ if (dout >= 32768) {
+ dout = 0;
+ }
}
// -- init() and main() -------------------------------------------------------