summaryrefslogtreecommitdiff
path: root/software/hhd70dongle/hhd70dongle.c
diff options
context:
space:
mode:
authorBernhard Tittelbach <xro@realraum.at>2012-05-17 06:14:25 +0000
committerBernhard Tittelbach <xro@realraum.at>2012-05-17 06:14:25 +0000
commit241a3d8edf2742a91e4b7516237fe55324eedeb6 (patch)
tree526f1c30862e60bd87d5f23cc04a016b71cbdcf1 /software/hhd70dongle/hhd70dongle.c
parentusb lib (diff)
spi and c1101 lib needs to be cleanly separated, code needs to be tested and finished
git-svn-id: https://svn.spreadspace.org/mur.sat@416 7de4ea59-55d0-425e-a1af-a3118ea81d4c
Diffstat (limited to 'software/hhd70dongle/hhd70dongle.c')
-rw-r--r--software/hhd70dongle/hhd70dongle.c43
1 files changed, 42 insertions, 1 deletions
diff --git a/software/hhd70dongle/hhd70dongle.c b/software/hhd70dongle/hhd70dongle.c
index 03b4e06..85d9d0f 100644
--- a/software/hhd70dongle/hhd70dongle.c
+++ b/software/hhd70dongle/hhd70dongle.c
@@ -11,7 +11,7 @@
* Please visit the project hompage at sat.mur.at for further information.
*
*
- * Copyright (C) 2011 Christian Pointner <equinox@mur.at>
+ * Copyright (C) 2012 Bernhard Tittelbach <xro@realraum.at>
*
* This file is part of mur.sat.
*
@@ -36,26 +36,67 @@
#include "spi.h"
#include "usb_rawhid.h"
+#define ADCMUX_INTERNALTEMP 0b100111
+#define ADCMUX_ADC12 0b100100
+
#define CPU_PRESCALE(n) (CLKPR = 0x80, CLKPR = (n))
+#define ADC_PRESCALER 0
uint8_t read_buffer[64]; // buffer for reading usb signals
uint8_t write_buffer[64]; // buffer for writing usb signals
+//TODOs:
+// * make as much use of sleep modes as possible
+// * use adc noise canceler (i.e. automatic sampling during cpu sleep)
+// * define and listen for an usb_hid reset command -> jump to bootload address
+// * read atmega temp
+// * safely save state in eeprom (2 memory regions, only use the one with the "written successfully bit" which is written last)
+
+
+int16_t adc_read(uint8_t mux)
+{
+ uint8_t low;
+ char aref = 0b11000000;
+ ADCSRA = (1<<ADEN) | ADC_PRESCALER; // enable ADC
+ ADCSRB = (1<<ADHSM) | (mux & 0x20); // high speed mode
+ ADMUX = aref | (mux & 0x1F); // configure mux input
+ ADCSRA = (1<<ADEN) | ADC_PRESCALER | (1<<ADSC); // start the conversion
+ while (ADCSRA & (1<<ADSC)) ; // wait for result
+ low = ADCL; // must read LSB first
+ ADCSRA &= ~(1<<ADEN); // disable ADC
+ return (ADCH << 8) | low; // must read MSB only once!
+}
+
int main(void)
{
CPU_PRESCALE(0);
led_init();
spi_init();
usb_init();
+ // set PB5/ADC12 to INPUT (c1101 temp sensor)
+ DDRB &= ~(1<<DDB5);
while (!usb_configured()) /* wait */ ;
//int8_t r = usb_rawhid_recv(read_buffer, 0);
//usb_rawhid_send(write_buffer, 23);
+ usb_rawhid_send("hhd70dongle ready",17);
+
+ int16_t c1101_temp = adc_read(ADCMUX_ADC12);
+ int16_t internal_temp = adc_read(ADCMUX_INTERNALTEMP);
for(;;)
{
_delay_ms(250);
led_toggle();
+ c1101_temp = adc_read(ADCMUX_ADC12);
+ internal_temp = adc_read(ADCMUX_INTERNALTEMP);
+ usb_rawhid_send("temp c1101: ",12);
+ write_buffer[0] = '0' + c1101_temp/26;
+ write_buffer[1] = 0;
+ usb_rawhid_send(write_buffer,1);
+ usb_rawhid_send("temp atmega: ",13);
+ write_buffer[0] = '0' + internal_temp/26;
+ usb_rawhid_send(write_buffer,1);
char buf[10];
unsigned int len;
spi_read(sizeof(buf),buf,&len);