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"]};
16 % if member.get("mode", None) == "pwm":
17 DDR${member["port"]} |= (1<<${member["pin"]});
18 ${device["pwm"].get(member["port"]+str(member["pin"]))[2]}
19 % elif member.get("mode", None) == "output":
20 DDR${member["port"]} |= (1<<${member["pin"]});
24 //${modulevar("state", None, "B", callbacks=(2, 2))}
25 void ${setter("state")} (const comm_callback_descriptor* cb, void* argbuf_end){
26 uint8_t arg=((uint8_t*)cb->argbuf)[0];
28 PORT${member["port"]} |= (1<<${member["pin"]});
30 PORT${member["port"]} &= ~(1<<${member["pin"]});
35 void ${getter("state")} (const comm_callback_descriptor* cb, void* argbuf_end){
38 uart_putc(!!(PIN${member["port"]} & (1<<${member["pin"]})));
41 //${modulevar("direction", None, "B", callbacks=(2, 2))}
42 void ${setter("direction")} (const comm_callback_descriptor* cb, void* argbuf_end){
43 uint8_t arg=((uint8_t*)cb->argbuf)[0];
44 DDR${member["port"]} &= ~(1<<${member["pin"]});
46 DDR${member["port"]} |= (1<<${member["pin"]});
48 DDR${member["port"]} &= ~(1<<${member["pin"]});
53 void ${getter("direction")} (const comm_callback_descriptor* cb, void* argbuf_end){
56 uart_putc(!!(DDR${member["port"]} & (1<<${member["pin"]})));
59 % if device["adc"].get(member["port"]+str(member["pin"])):
60 //${modulevar("analog", None, "B", callbacks=(2, None))}
61 void ${getter("analog")} (const comm_callback_descriptor* cb, void* argbuf_end){
64 #if defined(__AVR_ATmega48__) ||defined(__AVR_ATmega88__) || defined(__AVR_ATmega168__) || defined(__AVR_ATmega48P__) || defined(__AVR_ATmega88P__) || defined(__AVR_ATmega168P__) || defined(__AVR_ATmega328P__)
66 ADMUX |= ${device["adc"].get(member["port"]+str(member["pin"]))};
67 #elif defined(__AVR_ATmega2560__) || defined(__AVR_ATmega2561__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega1281__) || defined(__AVR_ATmega640__)
70 ADMUX |= ${device["adc"].get(member["port"]+str(member["pin"]))}&0x1F;
71 ADCSRB |= ${device["adc"].get(member["port"]+str(member["pin"]))}&0x20>>2;
73 while(!(ADCSRA&(1<<ADIF))); //wait for conversion to finish
75 ADCSRA |= (1<<ADIF); //reset the interrupt flag
79 % if device["pwm"].get(member["port"]+str(member["pin"])):
80 //${modulevar("pwm", None, "B", callbacks=(2, 2))}
81 void ${setter("pwm")} (const comm_callback_descriptor* cb, void* argbuf_end){
82 uint8_t arg=((uint8_t*)cb->argbuf)[0];
83 OCR${device["pwm"].get(member["port"]+str(member["pin"]))[0]}${device["pwm"].get(member["port"]+str(member["pin"]))[1]} = arg;
88 void ${getter("pwm")} (const comm_callback_descriptor* cb, void* argbuf_end){
91 uart_putc(OCR${device["pwm"].get(member["port"]+str(member["pin"]))[0]}${device["pwm"].get(member["port"]+str(member["pin"]))[1]});
94 //${modulevar("pwm_enabled", None, "B", callbacks=(2, 2))}
95 void ${getter("pwm_enabled")} (const comm_callback_descriptor* cb, void* argbuf_end){
96 //FIXME not implemented
101 void ${setter("pwm_enabled")} (const comm_callback_descriptor* cb, void* argbuf_end){
102 uint8_t arg=((uint8_t*)cb->argbuf)[0];
104 ${device["pwm"].get(member["port"]+str(member["pin"]))[2]}
106 ${device["pwm"].get(member["port"]+str(member["pin"]))[3]}