summaryrefslogtreecommitdiff
path: root/firmware
diff options
context:
space:
mode:
Diffstat (limited to 'firmware')
-rw-r--r--firmware/VirtualSerial.c93
1 files changed, 93 insertions, 0 deletions
diff --git a/firmware/VirtualSerial.c b/firmware/VirtualSerial.c
index 0fdc31c..cc06237 100644
--- a/firmware/VirtualSerial.c
+++ b/firmware/VirtualSerial.c
@@ -40,6 +40,8 @@
static int running = true;
+void CheckACMStatus(void);
+
/** LUFA CDC Class driver interface configuration and state information. This structure is
* passed to all CDC Class driver functions, so that multiple instances of the same class
* within a device can be differentiated from one another.
@@ -90,6 +92,85 @@ void lock_timer_reset(void)
lock_timer_ticks = 0;
}
+#define LM74_SIO PD4
+#define LM74_SCL PD5
+#define LM74_CS PD3
+
+/**
+ * Data is clocked out on the falling edge of the serial clock (SC), while data is clocked in on the rising edge of SC.
+ */
+void lm74_transaction(uint8_t out1, uint8_t out2, uint8_t *in1, uint8_t *in2)
+{
+/*
+ for(int i = 0; i < 8; i++)
+ {
+ PORTD |= (out1 & 0x01) << LM74_SIO;
+ PORTD |= _BV(LM74_SCL);
+ PORTD &= ~_BV(LM74_SCL);
+ out1 >>= 1;
+ }
+
+ for(int i = 0; i < 8; i++)
+ {
+ PORTD |= (out2 & 0x01) << LM74_SIO;
+ PORTD |= _BV(LM74_SCL);
+ PORTD &= ~_BV(LM74_SCL);
+ out2 >>= 1;
+ }
+*/
+/*
+ for(int i = 0; i < 16; i++)
+ {
+// PORTD |= (out2 & 0x01) << LM74_SIO;
+ PORTD |= _BV(LM74_SCL);
+ _delay_ms(10);
+ PORTD &= ~_BV(LM74_SCL);
+ _delay_ms(10);
+ }
+*/
+ uint16_t temp;
+
+ PORTD &= ~_BV(LM74_CS);
+ _delay_us(100);
+ for(int i=0; i<16; i++) {
+ temp <<= 1;
+ PORTD |= _BV(LM74_SCL);
+ _delay_us(100);
+// if (SIO == true)
+// temp |= 1;
+ PORTD &= ~_BV(LM74_SCL);
+ _delay_us(100);
+ }
+
+ PORTD |= _BV(LM74_CS);
+}
+
+void lm74_init(void)
+{
+ PORTD |= (1 << LM74_SCL) | (1 << LM74_CS);
+
+ DDRD |= (1 << LM74_SCL) | (1 << LM74_CS);
+ DDRD &= ~(1 << LM74_SIO);
+
+ PORTD |= (1 << LM74_SIO); // Enable pull-up
+
+ uint8_t d1, d2;
+ _delay_ms(100);
+ lm74_transaction(0x5a, 0xa5, &d1, &d2);
+ _delay_ms(100);
+ lm74_transaction(0x5a, 0xa5, &d1, &d2);
+ _delay_ms(100);
+ lm74_transaction(0x5a, 0xa5, &d1, &d2);
+ _delay_ms(100);
+ lm74_transaction(0x5a, 0xa5, &d1, &d2);
+ _delay_ms(100);
+ lm74_transaction(0x5a, 0xa5, &d1, &d2);
+ _delay_ms(100);
+ lm74_transaction(0x5a, 0xa5, &d1, &d2);
+ _delay_ms(100);
+ lm74_transaction(0x5a, 0xa5, &d1, &d2);
+}
+
/** Main program entry point. This routine contains the overall program flow, including initial
* setup of all components and the main program loop.
*/
@@ -98,7 +179,11 @@ int main(void)
DDRB = 1 << PB0 | 1 << PB4 | 0 << PB5;
PORTB = 0 << PB0;
+ // Disables pull-ups
+ PORTD = 0;
+
SetupHardware();
+ lm74_init();
lock_timer_setup();
@@ -183,6 +268,14 @@ void handle_command(const char *buf)
PORTB &= ~(1 << PB4);
PORTB &= ~(1 << PB0);
}
+
+ else if (strcmp("temp", buf) == 0)
+ {
+ uint8_t data = 0x5a;
+
+ uint8_t d1, d2;
+ lm74_transaction(0x5a, 0xa5, &d1, &d2);
+ }
}
void CheckACMStatus()