/
lab-irkit2.h
185 lines (155 loc) · 5.55 KB
/
lab-irkit2.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
// lab-irkit.h
//
// Authors: Hans-Gert Dahmen <sexyludernatascha@gmail.com>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
// MA 02110-1301, USA.
/*
* IR codes are stored in an array of on/off pulse lengths.
* As transmissions must always start with a one and consist
* of alternating ones and zeroes, every even index in the
* array will be a one-pulse and every odd array index
* will be a zero-pulse.
*/
#ifndef _H_LAB_IRKIT
#define _H_LAB_IRKIT
#include <avr/io.h>
//one tick is 16 µS long
//#define IR_TICK_US 16
#ifndef F_CPU
#error F_CPU not defined
#else
//standart IR frequencies, define your own here
#define IR_FREQ30K (uint16_t)(F_CPU/30000UL)
#define IR_FREQ33K (uint16_t)(F_CPU/33000UL)
#define IR_FREQ36K (uint16_t)(F_CPU/36000UL)
#define IR_FREQ38K (uint16_t)(F_CPU/38000UL)
#define IR_FREQ40K (uint16_t)(F_CPU/40000UL)
#define IR_FREQ56K (uint16_t)(F_CPU/56000UL)
#define IR_FREQ455K (uint16_t)(F_CPU/455000UL)
#endif
//define output PORT
#define IRPORT PORTA
#define IRDDR DDRA
#define IRUSEDPORTS 0x3
//define how long a carrier pulse last 0..1
//select 0.5 for normal LED mode or
//less values if you overcurrent the IR LEDs
#define IR_pulse_width 0.2f
//max SRAM usage
#define IR_MAX_SRAM 512
//see datasheet: http://www.princeton.com.tw/downloadprocess/downloadfile.asp?mydownload=PT2248.pdf
#define IR_PT2248_Carrier IR_FREQ38K
#define IR_PT2248_pulselength 422
#define IR_PT2248_oneCode 0b0001
#define IR_PT2248_oneCodelength 4
#define IR_PT2248_zeroCode 0b0111
#define IR_PT2248_zeroCodelength 4
#define IR_PT2248_header 0
#define IR_PT2248_headerlength 0
#define IR_PhilipsRC5_Carrier IR_FREQ36K
#define IR_PhilipsRC5_pulselength 889
#define IR_PhilipsRC5_oneCode 0b10
#define IR_PhilipsRC5_oneCodelength 2
#define IR_PhilipsRC5_zeroCode 0b01
#define IR_PhilipsRC5_zeroCodelength 2
#define IR_PhilipsRC5_header 0
#define IR_PhilipsRC5_headerlength 0
#define IR_PhilipsRC6_Carrier IR_FREQ36K
#define IR_PhilipsRC6_pulselength 444
#define IR_PhilipsRC6_oneCode 0b10
#define IR_PhilipsRC6_oneCodelength 2
#define IR_PhilipsRC6_zeroCode 0b01
#define IR_PhilipsRC6_zeroCodelength 2
#define IR_PhilipsRC6_header 0
#define IR_PhilipsRC6_headerlength 0
#define IR_SIRC_Carrier IR_FREQ40K
#define IR_SIRC_pulselength 600
#define IR_SIRC_oneCode 0b100
#define IR_SIRC_oneCodelength 3
#define IR_SIRC_zeroCode 0b10
#define IR_SIRC_zeroCodelength 2
#define IR_SIRC_header 0b11110
#define IR_SIRC_headerlength 5
#define IR_Sharp_Carrier IR_FREQ38K
#define IR_Sharp_pulselength 320
#define IR_Sharp_oneCode 0b100000
#define IR_Sharp_oneCodelength 6
#define IR_Sharp_zeroCode 0b100
#define IR_Sharp_zeroCodelength 3
#define IR_Sharp_header 0
#define IR_Sharp_headerlength 0
#define IR_NokiaNRC17_Carrier IR_FREQ38K
#define IR_NokiaNRC17_pulselength 500
#define IR_NokiaNRC17_oneCode 0b10
#define IR_NokiaNRC17_oneCodelength 2
#define IR_NokiaNRC17_zeroCode 0b01
#define IR_NokiaNRC17_zeroCodelength 2
#define IR_NokiaNRC17_header 0b100000
#define IR_NokiaNRC17_headerlength 6
#define IR_NEC_Carrier IR_FREQ38K
#define IR_NEC_pulselength 560
#define IR_NEC_oneCode 0b1000
#define IR_NEC_oneCodelength 4
#define IR_NEC_zeroCode 0b10
#define IR_NEC_zeroCodelength 2
#define IR_NEC_header 0b111111111111111100000000
#define IR_NEC_headerlength 24
#define IR_JVC_Carrier IR_FREQ38K
#define IR_JVC_pulselength 526
#define IR_JVC_oneCode 0b1000
#define IR_JVC_oneCodelength 4
#define IR_JVC_zeroCode 0b10
#define IR_JVC_zeroCodelength 2
#define IR_JVC_header 0b111111111111111100000000
#define IR_JVC_headerlength 24
/*
Code example:
#include <stdio.h>
#include <stdlib.h>
#include "lab-irkit2.h"
int main(void)
{
//initialize ir subsystem
ir_init(IR_NEC_Carrier, IR_NEC_pulselength);
uint8_t codelength=0;
ir_genHeader(0, IR_NEC_header, IR_NEC_headerlength); //generate header
codelength=ir_genCode(IR_NEC_headerlength,0,IR_NEC_oneCode,IR_NEC_oneCodelength,IR_NEC_zeroCode,IR_NEC_zeroCodelength,0b00010000110010001110000100011110, 32); //generate code
while (1)
{
ir_sendCode(codelength); //transmit code
}
}
*/
// stop TIMER1, disable IRPORT
#define FREQGEN_OFF() TCCR1B = 0; IRPORT&=IRDDR
// start TIMER1, reset timer count
#define FREQGEN_ON() TCNT1 = 0; TCCR1B = _BV(WGM12)|_BV(CS10) //counter is running now
//function prototypes
uint8_t ir_init(uint16_t freq, uint16_t pulselength);
void ir_disable(void);
uint16_t ir_genCode(uint8_t headerlength, uint8_t channel, uint8_t oneCode, uint8_t oneCode_length, uint8_t zeroCode,uint8_t zeroCode_length, uint32_t bitCode, uint8_t codeLen);
uint8_t ir_genHeader(uint8_t channel, uint32_t headerCode, uint8_t headerLen);
uint8_t ir_freqInit(uint16_t freq, uint16_t pulselength);
void ir_sendCode(uint16_t codeLen);
uint8_t transmission_pending(void);
//work in progress
/*typedef struct {
uint16_t oneOntime;
uint16_t oneOfftime;
uint16_t zeroOntime;
uint16_t zeroOfftime;
} ir_proto;*/
#endif //_H_LAB_IRKIT