2 Copyright (C) 2012 jaseg <s@jaseg.de>
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 version 3 as published by the Free Software Foundation.
11 void ${init_function()} (void){
12 % if device["adc"].get(member["port"]+str(member["pin"])):
13 ADMUX |= REFS0 | ADLAR;
14 ADCSRA |= ADEN | ${device["adc"]["prescaler_bits"]};
18 //${modulevar("state", None, "B", callbacks=(2, 2))}
19 void ${setter("state")} (const comm_callback_descriptor* cb, void* argbuf_end){
20 uint8_t arg=((uint8_t*)cb->argbuf)[0];
22 PORT${member["port"]} |= (1<<${member["pin"]});
24 PORT${member["port"]} &= ~(1<<${member["pin"]});
29 void ${getter("state")} (const comm_callback_descriptor* cb, void* argbuf_end){
32 uart_putc(!!(PIN${member["port"]} & (1<<${member["pin"]})));
35 //${modulevar("direction", None, "B", callbacks=(2, 2))}
36 void ${setter("direction")} (const comm_callback_descriptor* cb, void* argbuf_end){
37 uint8_t arg=((uint8_t*)cb->argbuf)[0];
38 DDR${member["port"]} &= ~(1<<${member["pin"]});
40 DDR${member["port"]} |= (1<<${member["pin"]});
42 DDR${member["port"]} &= ~(1<<${member["pin"]});
47 void ${getter("direction")} (const comm_callback_descriptor* cb, void* argbuf_end){
50 uart_putc(!!(DDR${member["port"]} & (1<<${member["pin"]})));
53 % if device["adc"].get(member["port"]+str(member["pin"])):
54 //${modulevar("analog", None, "B", callbacks=(2, None))}
55 void ${getter("analog")} (const comm_callback_descriptor* cb, void* argbuf_end){
58 #if defined(__AVR_ATmega48__) ||defined(__AVR_ATmega88__) || defined(__AVR_ATmega168__) || defined(__AVR_ATmega48P__) || defined(__AVR_ATmega88P__) || defined(__AVR_ATmega168P__) || defined(__AVR_ATmega328P__)
60 ADMUX |= ${device["adc"].get(member["port"]+str(member["pin"]))};
61 #elif defined(__AVR_ATmega2560__) || defined(__AVR_ATmega2561__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega1281__) || defined(__AVR_ATmega640__)
64 ADMUX |= ${device["adc"].get(member["port"]+str(member["pin"]))}&0x1F;
65 ADCSRB |= ${device["adc"].get(member["port"]+str(member["pin"]))}&0x20>>2;
67 while(!(ADCSRA&(1<<ADIF))); //wait for conversion to finish
69 ADCSRA |= (1<<ADIF); //reset the interrupt flag
73 % if device["pwm"].get(member["port"]+str(member["pin"])):
74 //${modulevar("pwm", None, "B", callbacks=(2, 2))}
75 void ${setter("pwm")} (const comm_callback_descriptor* cb, void* argbuf_end){
76 uint8_t arg=((uint8_t*)cb->argbuf)[0];
77 OCR${device["pwm"].get(member["port"]+str(member["pin"]))[0]}${device["pwm"].get(member["port"]+str(member["pin"]))[1]} = arg;
82 void ${getter("pwm")} (const comm_callback_descriptor* cb, void* argbuf_end){
85 uart_putc(OCR${device["pwm"].get(member["port"]+str(member["pin"]))[0]}${device["pwm"].get(member["port"]+str(member["pin"]))[1]});
88 //${modulevar("pwm_enabled", None, "B", callbacks=(2, 2))}
89 void ${getter("pwm_enabled")} (const comm_callback_descriptor* cb, void* argbuf_end){
90 //FIXME not implemented
95 void ${setter("pwm_enabled")} (const comm_callback_descriptor* cb, void* argbuf_end){
96 uint8_t arg=((uint8_t*)cb->argbuf)[0];
98 ${device["pwm"].get(member["port"]+str(member["pin"]))[2]}
100 ${device["pwm"].get(member["port"]+str(member["pin"]))[3]}