PIO hinzugefügt
This commit is contained in:
parent
99c282566f
commit
419e37eeae
14 changed files with 954 additions and 75 deletions
248
pio/dmode.h
Normal file
248
pio/dmode.h
Normal file
|
@ -0,0 +1,248 @@
|
|||
/***
|
||||
* dmode.h
|
||||
* This file is part of the PIO library.
|
||||
* For license information see "pio.h" in the parent directory.
|
||||
*/
|
||||
|
||||
#if !defined(PIOLIB) || PIOLIB < 100
|
||||
#error This file should be included directly. Use "pio.h" instead.
|
||||
#endif
|
||||
|
||||
#ifndef PIO_DMODE_H
|
||||
#define PIO_DMODE_H
|
||||
|
||||
#define dMode(A, B) dMode_(A, B)
|
||||
#define dMode_(A, B) DMODE ## _ ## A ## _ ## B
|
||||
|
||||
#ifdef PA0
|
||||
#define DMODE_A0_1 DDRA |= 0x01
|
||||
#define DMODE_A0_0 DDRA &= 0xFE
|
||||
#else
|
||||
#define DMODE_A0_1 # Pin A0 not supported on this MCU!
|
||||
#define DMODE_A0_0 DMODE_A0_1
|
||||
#endif
|
||||
#ifdef PA1
|
||||
#define DMODE_A1_1 DDRA |= 0x02
|
||||
#define DMODE_A1_0 DDRA &= 0xFD
|
||||
#else
|
||||
#define DMODE_A1_1 # Pin A1 not supported on this MCU!
|
||||
#define DMODE_A1_0 DMODE_A1_1
|
||||
#endif
|
||||
#ifdef PA2
|
||||
#define DMODE_A2_1 DDRA |= 0x04
|
||||
#define DMODE_A2_0 DDRA &= 0xFB
|
||||
#else
|
||||
#define DMODE_A2_1 # Pin A2 not supported on this MCU!
|
||||
#define DMODE_A2_0 DMODE_A2_1
|
||||
#endif
|
||||
#ifdef PA3
|
||||
#define DMODE_A3_1 DDRA |= 0x08
|
||||
#define DMODE_A3_0 DDRA &= 0xF7
|
||||
#else
|
||||
#define DMODE_A3_1 # Pin A3 not supported on this MCU!
|
||||
#define DMODE_A3_0 DMODE_A3_1
|
||||
#endif
|
||||
#ifdef PA4
|
||||
#define DMODE_A4_1 DDRA |= 0x10
|
||||
#define DMODE_A4_0 DDRA &= 0xEF
|
||||
#else
|
||||
#define DMODE_A4_1 # Pin A4 not supported on this MCU!
|
||||
#define DMODE_A4_0 DMODE_A4_1
|
||||
#endif
|
||||
#ifdef PA5
|
||||
#define DMODE_A5_1 DDRA |= 0x20
|
||||
#define DMODE_A5_0 DDRA &= 0xDF
|
||||
#else
|
||||
#define DMODE_A5_1 # Pin A5 not supported on this MCU!
|
||||
#define DMODE_A5_0 DMODE_A5_1
|
||||
#endif
|
||||
#ifdef PA6
|
||||
#define DMODE_A6_1 DDRA |= 0x40
|
||||
#define DMODE_A6_0 DDRA &= 0xBF
|
||||
#else
|
||||
#define DMODE_A6_1 # Pin A6 not supported on this MCU!
|
||||
#define DMODE_A6_0 DMODE_A6_1
|
||||
#endif
|
||||
#ifdef PA7
|
||||
#define DMODE_A7_1 DDRA |= 0x80
|
||||
#define DMODE_A7_0 DDRA &= 0x7F
|
||||
#else
|
||||
#define DMODE_A7_1 # Pin A7 not supported on this MCU!
|
||||
#define DMODE_A7_0 DMODE_A7_1
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef PB0
|
||||
#define DMODE_B0_1 DDRB |= 0x01
|
||||
#define DMODE_B0_0 DDRB &= 0xFE
|
||||
#else
|
||||
#define DMODE_B0_1 # Pin B0 not supported on this MCU!
|
||||
#define DMODE_B0_0 DMODE_B0_1
|
||||
#endif
|
||||
#ifdef PB1
|
||||
#define DMODE_B1_1 DDRB |= 0x02
|
||||
#define DMODE_B1_0 DDRB &= 0xFD
|
||||
#else
|
||||
#define DMODE_B1_1 # Pin B1 not supported on this MCU!
|
||||
#define DMODE_B1_0 DMODE_B1_1
|
||||
#endif
|
||||
#ifdef PB2
|
||||
#define DMODE_B2_1 DDRB |= 0x04
|
||||
#define DMODE_B2_0 DDRB &= 0xFB
|
||||
#else
|
||||
#define DMODE_B2_1 # Pin B2 not supported on this MCU!
|
||||
#define DMODE_B2_0 DMODE_B2_1
|
||||
#endif
|
||||
#ifdef PB3
|
||||
#define DMODE_B3_1 DDRB |= 0x08
|
||||
#define DMODE_B3_0 DDRB &= 0xF7
|
||||
#else
|
||||
#define DMODE_B3_1 # Pin B3 not supported on this MCU!
|
||||
#define DMODE_B3_0 DMODE_B3_1
|
||||
#endif
|
||||
#ifdef PB4
|
||||
#define DMODE_B4_1 DDRB |= 0x10
|
||||
#define DMODE_B4_0 DDRB &= 0xEF
|
||||
#else
|
||||
#define DMODE_B4_1 # Pin B4 not supported on this MCU!
|
||||
#define DMODE_B4_0 DMODE_B4_1
|
||||
#endif
|
||||
#ifdef PB5
|
||||
#define DMODE_B5_1 DDRB |= 0x20
|
||||
#define DMODE_B5_0 DDRB &= 0xDF
|
||||
#else
|
||||
#define DMODE_B5_1 # Pin B5 not supported on this MCU!
|
||||
#define DMODE_B5_0 DMODE_B5_1
|
||||
#endif
|
||||
#ifdef PB6
|
||||
#define DMODE_B6_1 DDRB |= 0x40
|
||||
#define DMODE_B6_0 DDRB &= 0xBF
|
||||
#else
|
||||
#define DMODE_B6_1 # Pin B6 not supported on this MCU!
|
||||
#define DMODE_B6_0 DMODE_B6_1
|
||||
#endif
|
||||
#ifdef PB7
|
||||
#define DMODE_B7_1 DDRB |= 0x80
|
||||
#define DMODE_B7_0 DDRB &= 0x7F
|
||||
#else
|
||||
#define DMODE_B7_1 # Pin B7 not supported on this MCU!
|
||||
#define DMODE_B7_0 DMODE_B7_1
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef PC0
|
||||
#define DMODE_C0_1 DDRC |= 0x01
|
||||
#define DMODE_C0_0 DDRC &= 0xFE
|
||||
#else
|
||||
#define DMODE_C0_1 # Pin C0 not supported on this MCU!
|
||||
#define DMODE_C0_0 DMODE_C0_1
|
||||
#endif
|
||||
#ifdef PC1
|
||||
#define DMODE_C1_1 DDRC |= 0x02
|
||||
#define DMODE_C1_0 DDRC &= 0xFD
|
||||
#else
|
||||
#define DMODE_C1_1 # Pin C1 not supported on this MCU!
|
||||
#define DMODE_C1_0 DMODE_C1_1
|
||||
#endif
|
||||
#ifdef PC2
|
||||
#define DMODE_C2_1 DDRC |= 0x04
|
||||
#define DMODE_C2_0 DDRC &= 0xFB
|
||||
#else
|
||||
#define DMODE_C2_1 # Pin C2 not supported on this MCU!
|
||||
#define DMODE_C2_0 DMODE_C2_1
|
||||
#endif
|
||||
#ifdef PC3
|
||||
#define DMODE_C3_1 DDRC |= 0x08
|
||||
#define DMODE_C3_0 DDRC &= 0xF7
|
||||
#else
|
||||
#define DMODE_C3_1 # Pin C3 not supported on this MCU!
|
||||
#define DMODE_C3_0 DMODE_C3_1
|
||||
#endif
|
||||
#ifdef PC4
|
||||
#define DMODE_C4_1 DDRC |= 0x10
|
||||
#define DMODE_C4_0 DDRC &= 0xEF
|
||||
#else
|
||||
#define DMODE_C4_1 # Pin C4 not supported on this MCU!
|
||||
#define DMODE_C4_0 DMODE_C4_1
|
||||
#endif
|
||||
#ifdef PC5
|
||||
#define DMODE_C5_1 DDRC |= 0x20
|
||||
#define DMODE_C5_0 DDRC &= 0xDF
|
||||
#else
|
||||
#define DMODE_C5_1 # Pin C5 not supported on this MCU!
|
||||
#define DMODE_C5_0 DMODE_C5_1
|
||||
#endif
|
||||
#ifdef PC6
|
||||
#define DMODE_C6_1 DDRC |= 0x40
|
||||
#define DMODE_C6_0 DDRC &= 0xBF
|
||||
#else
|
||||
#define DMODE_C6_1 # Pin C6 not supported on this MCU!
|
||||
#define DMODE_C6_0 DMODE_C6_1
|
||||
#endif
|
||||
#ifdef PC7
|
||||
#define DMODE_C7_1 DDRC |= 0x80
|
||||
#define DMODE_C7_0 DDRC &= 0x7F
|
||||
#else
|
||||
#define DMODE_C7_1 # Pin C7 not supported on this MCU!
|
||||
#define DMODE_C7_0 DMODE_C7_1
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef PD0
|
||||
#define DMODE_D0_1 DDRD |= 0x01
|
||||
#define DMODE_D0_0 DDRD &= 0xFE
|
||||
#else
|
||||
#define DMODE_D0_1 # Pin D0 not supported on this MCU!
|
||||
#define DMODE_D0_0 DMODE_D0_1
|
||||
#endif
|
||||
#ifdef PD1
|
||||
#define DMODE_D1_1 DDRD |= 0x02
|
||||
#define DMODE_D1_0 DDRD &= 0xFD
|
||||
#else
|
||||
#define DMODE_D1_1 # Pin D1 not supported on this MCU!
|
||||
#define DMODE_D1_0 DMODE_D1_1
|
||||
#endif
|
||||
#ifdef PD2
|
||||
#define DMODE_D2_1 DDRD |= 0x04
|
||||
#define DMODE_D2_0 DDRD &= 0xFB
|
||||
#else
|
||||
#define DMODE_D2_1 # Pin D2 not supported on this MCU!
|
||||
#define DMODE_D2_0 DMODE_D2_1
|
||||
#endif
|
||||
#ifdef PD3
|
||||
#define DMODE_D3_1 DDRD |= 0x08
|
||||
#define DMODE_D3_0 DDRD &= 0xF7
|
||||
#else
|
||||
#define DMODE_D3_1 # Pin D3 not supported on this MCU!
|
||||
#define DMODE_D3_0 DMODE_D3_1
|
||||
#endif
|
||||
#ifdef PD4
|
||||
#define DMODE_D4_1 DDRD |= 0x10
|
||||
#define DMODE_D4_0 DDRD &= 0xEF
|
||||
#else
|
||||
#define DMODE_D4_1 # Pin D4 not supported on this MCU!
|
||||
#define DMODE_D4_0 DMODE_D4_1
|
||||
#endif
|
||||
#ifdef PD5
|
||||
#define DMODE_D5_1 DDRD |= 0x20
|
||||
#define DMODE_D5_0 DDRD &= 0xDF
|
||||
#else
|
||||
#define DMODE_D5_1 # Pin D5 not supported on this MCU!
|
||||
#define DMODE_D5_0 DMODE_D5_1
|
||||
#endif
|
||||
#ifdef PD6
|
||||
#define DMODE_D6_1 DDRD |= 0x40
|
||||
#define DMODE_D6_0 DDRD &= 0xBF
|
||||
#else
|
||||
#define DMODE_D6_1 # Pin D6 not supported on this MCU!
|
||||
#define DMODE_D6_0 DMODE_D6_1
|
||||
#endif
|
||||
#ifdef PD7
|
||||
#define DMODE_D7_1 DDRD |= 0x80
|
||||
#define DMODE_D7_0 DDRD &= 0x7F
|
||||
#else
|
||||
#define DMODE_D7_1 # Pin D7 not supported on this MCU!
|
||||
#define DMODE_D7_0 DMODE_D7_1
|
||||
#endif
|
||||
|
||||
#endif // PIO_DMODE_H
|
183
pio/dread.h
Normal file
183
pio/dread.h
Normal file
|
@ -0,0 +1,183 @@
|
|||
/***
|
||||
* dread.h
|
||||
* This file is part of the PIO library.
|
||||
* For license information see "pio.h" in the parent directory.
|
||||
*/
|
||||
|
||||
#if !defined(PIOLIB) || PIOLIB < 100
|
||||
#error This file should be included directly. Use "pio.h" instead.
|
||||
#endif
|
||||
|
||||
#ifndef PIO_DREAD_H
|
||||
#define PIO_DREAD_H
|
||||
|
||||
#define dRead(A) dRead_(A)
|
||||
#define dRead_(A) DREAD ## _ ## A
|
||||
|
||||
#ifdef PA0
|
||||
#define DREAD_A0 (PINA & 0x01)
|
||||
#else
|
||||
#define DREAD_A0 # Pin A0 not supported on this MCU!
|
||||
#endif
|
||||
#ifdef PA1
|
||||
#define DREAD_A1 (PINA & 0x02)
|
||||
#else
|
||||
#define DREAD_A1 # Pin A1 not supported on this MCU!
|
||||
#endif
|
||||
#ifdef PA2
|
||||
#define DREAD_A2 (PINA & 0x04)
|
||||
#else
|
||||
#define DREAD_A2 # Pin A2 not supported on this MCU!
|
||||
#endif
|
||||
#ifdef PA3
|
||||
#define DREAD_A3 (PINA & 0x08)
|
||||
#else
|
||||
#define DREAD_A3 # Pin A3 not supported on this MCU!
|
||||
#endif
|
||||
#ifdef PA4
|
||||
#define DREAD_A4 (PINA & 0x10)
|
||||
#else
|
||||
#define DREAD_A4 # Pin A4 not supported on this MCU!
|
||||
#endif
|
||||
#ifdef PA5
|
||||
#define DREAD_A5 (PINA & 0x20)
|
||||
#else
|
||||
#define DREAD_A5 # Pin A5 not supported on this MCU!
|
||||
#endif
|
||||
#ifdef PA6
|
||||
#define DREAD_A6 (PINA & 0x40)
|
||||
#else
|
||||
#define DREAD_A6 # Pin A6 not supported on this MCU!
|
||||
#endif
|
||||
#ifdef PA7
|
||||
#define DREAD_A7 (PINA & 0x80)
|
||||
#else
|
||||
#define DREAD_A7 # Pin A7 not supported on this MCU!
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef PB0
|
||||
#define DREAD_B0 (PINB & 0x01)
|
||||
#else
|
||||
#define DREAD_B0 # Pin B0 not supported on this MCU!
|
||||
#endif
|
||||
#ifdef PB1
|
||||
#define DREAD_B1 (PINB & 0x02)
|
||||
#else
|
||||
#define DREAD_B1 # Pin B1 not supported on this MCU!
|
||||
#endif
|
||||
#ifdef PB2
|
||||
#define DREAD_B2 (PINB & 0x04)
|
||||
#else
|
||||
#define DREAD_B2 # Pin B2 not supported on this MCU!
|
||||
#endif
|
||||
#ifdef PB3
|
||||
#define DREAD_B3 (PINB & 0x08)
|
||||
#else
|
||||
#define DREAD_B3 # Pin B3 not supported on this MCU!
|
||||
#endif
|
||||
#ifdef PB4
|
||||
#define DREAD_B4 (PINB & 0x10)
|
||||
#else
|
||||
#define DREAD_B4 # Pin B4 not supported on this MCU!
|
||||
#endif
|
||||
#ifdef PB5
|
||||
#define DREAD_B5 (PINB & 0x20)
|
||||
#else
|
||||
#define DREAD_B5 # Pin B5 not supported on this MCU!
|
||||
#endif
|
||||
#ifdef PB6
|
||||
#define DREAD_B6 (PINB & 0x40)
|
||||
#else
|
||||
#define DREAD_B6 # Pin B6 not supported on this MCU!
|
||||
#endif
|
||||
#ifdef PB7
|
||||
#define DREAD_B7 (PINB & 0x80)
|
||||
#else
|
||||
#define DREAD_B7 # Pin B7 not supported on this MCU!
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef PC0
|
||||
#define DREAD_C0 (PINC & 0x01)
|
||||
#else
|
||||
#define DREAD_C0 # Pin C0 not supported on this MCU!
|
||||
#endif
|
||||
#ifdef PC1
|
||||
#define DREAD_C1 (PINC & 0x02)
|
||||
#else
|
||||
#define DREAD_C1 # Pin C1 not supported on this MCU!
|
||||
#endif
|
||||
#ifdef PC2
|
||||
#define DREAD_C2 (PINC & 0x04)
|
||||
#else
|
||||
#define DREAD_C2 # Pin C2 not supported on this MCU!
|
||||
#endif
|
||||
#ifdef PC3
|
||||
#define DREAD_C3 (PINC & 0x08)
|
||||
#else
|
||||
#define DREAD_C3 # Pin C3 not supported on this MCU!
|
||||
#endif
|
||||
#ifdef PC4
|
||||
#define DREAD_C4 (PINC & 0x10)
|
||||
#else
|
||||
#define DREAD_C4 # Pin C4 not supported on this MCU!
|
||||
#endif
|
||||
#ifdef PC5
|
||||
#define DREAD_C5 (PINC & 0x20)
|
||||
#else
|
||||
#define DREAD_C5 # Pin C5 not supported on this MCU!
|
||||
#endif
|
||||
#ifdef PC6
|
||||
#define DREAD_C6 (PINC & 0x40)
|
||||
#else
|
||||
#define DREAD_C6 # Pin C6 not supported on this MCU!
|
||||
#endif
|
||||
#ifdef PC7
|
||||
#define DREAD_C7 (PINC & 0x80)
|
||||
#else
|
||||
#define DREAD_C7 # Pin C7 not supported on this MCU!
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef PD0
|
||||
#define DREAD_D0 (PIND & 0x01)
|
||||
#else
|
||||
#define DREAD_D0 # Pin D0 not supported on this MCU!
|
||||
#endif
|
||||
#ifdef PD1
|
||||
#define DREAD_D1 (PIND & 0x02)
|
||||
#else
|
||||
#define DREAD_D1 # Pin D1 not supported on this MCU!
|
||||
#endif
|
||||
#ifdef PD2
|
||||
#define DREAD_D2 (PIND & 0x04)
|
||||
#else
|
||||
#define DREAD_D2 # Pin D2 not supported on this MCU!
|
||||
#endif
|
||||
#ifdef PD3
|
||||
#define DREAD_D3 (PIND & 0x08)
|
||||
#else
|
||||
#define DREAD_D3 # Pin D3 not supported on this MCU!
|
||||
#endif
|
||||
#ifdef PD4
|
||||
#define DREAD_D4 (PIND & 0x10)
|
||||
#else
|
||||
#define DREAD_D4 # Pin D4 not supported on this MCU!
|
||||
#endif
|
||||
#ifdef PD5
|
||||
#define DREAD_D5 (PIND & 0x20)
|
||||
#else
|
||||
#define DREAD_D5 # Pin D5 not supported on this MCU!
|
||||
#endif
|
||||
#ifdef PD6
|
||||
#define DREAD_D6 (PIND & 0x40)
|
||||
#else
|
||||
#define DREAD_D6 # Pin D6 not supported on this MCU!
|
||||
#endif
|
||||
#ifdef PD7
|
||||
#define DREAD_D7 (PIND & 0x80)
|
||||
#else
|
||||
#define DREAD_D7 # Pin D7 not supported on this MCU!
|
||||
#endif
|
||||
#endif // PIO_DREAD_H
|
249
pio/dwrite.h
Normal file
249
pio/dwrite.h
Normal file
|
@ -0,0 +1,249 @@
|
|||
/***
|
||||
* dwrite.h
|
||||
* This file is part of the PIO library.
|
||||
* For license information see "pio.h" in the parent directory.
|
||||
*/
|
||||
|
||||
#if !defined(PIOLIB) || PIOLIB < 100
|
||||
#error This file should be included directly. Use "pio.h" instead.
|
||||
#endif
|
||||
|
||||
#ifndef PIO_DWRITE_H
|
||||
#define PIO_DWRITE_H
|
||||
|
||||
#define dWrite(A, B) dWrite_(A, B)
|
||||
#define dWrite_(A, B) DWRITE ## _ ## A ## _ ## B
|
||||
|
||||
#ifdef PA0
|
||||
#define DWRITE_A0_1 PORTA |= 0x01
|
||||
#define DWRITE_A0_0 PORTA &= 0xFE
|
||||
#else
|
||||
#define DWRITE_A0_1 # Pin A0 not supported on this MCU!
|
||||
#define DWRITE_A0_0 DWRITE_A0_1
|
||||
#endif
|
||||
#ifdef PA1
|
||||
#define DWRITE_A1_1 PORTA |= 0x02
|
||||
#define DWRITE_A1_0 PORTA &= 0xFD
|
||||
#else
|
||||
#define DWRITE_A1_1 # Pin A1 not supported on this MCU!
|
||||
#define DWRITE_A1_0 DWRITE_A1_1
|
||||
#endif
|
||||
#ifdef PA2
|
||||
#define DWRITE_A2_1 PORTA |= 0x04
|
||||
#define DWRITE_A2_0 PORTA &= 0xFB
|
||||
#else
|
||||
#define DWRITE_A2_1 # Pin A2 not supported on this MCU!
|
||||
#define DWRITE_A2_0 DWRITE_A2_1
|
||||
#endif
|
||||
#ifdef PA3
|
||||
#define DWRITE_A3_1 PORTA |= 0x08
|
||||
#define DWRITE_A3_0 PORTA &= 0xF7
|
||||
#else
|
||||
#define DWRITE_A3_1 # Pin A3 not supported on this MCU!
|
||||
#define DWRITE_A3_0 DWRITE_A3_1
|
||||
#endif
|
||||
#ifdef PA4
|
||||
#define DWRITE_A4_1 PORTA |= 0x10
|
||||
#define DWRITE_A4_0 PORTA &= 0xEF
|
||||
#else
|
||||
#define DWRITE_A4_1 # Pin A4 not supported on this MCU!
|
||||
#define DWRITE_A4_0 DWRITE_A4_1
|
||||
#endif
|
||||
#ifdef PA5
|
||||
#define DWRITE_A5_1 PORTA |= 0x20
|
||||
#define DWRITE_A5_0 PORTA &= 0xDF
|
||||
#else
|
||||
#define DWRITE_A5_1 # Pin A5 not supported on this MCU!
|
||||
#define DWRITE_A5_0 DWRITE_A5_1
|
||||
#endif
|
||||
#ifdef PA6
|
||||
#define DWRITE_A6_1 PORTA |= 0x40
|
||||
#define DWRITE_A6_0 PORTA &= 0xBF
|
||||
#else
|
||||
#define DWRITE_A6_1 # Pin A6 not supported on this MCU!
|
||||
#define DWRITE_A6_0 DWRITE_A6_1
|
||||
#endif
|
||||
#ifdef PA7
|
||||
#define DWRITE_A7_1 PORTA |= 0x80
|
||||
#define DWRITE_A7_0 PORTA &= 0x7F
|
||||
#else
|
||||
#define DWRITE_A7_1 # Pin A7 not supported on this MCU!
|
||||
#define DWRITE_A7_0 DWRITE_A7_1
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef PB0
|
||||
#define DWRITE_B0_1 PORTB |= 0x01
|
||||
#define DWRITE_B0_0 PORTB &= 0xFE
|
||||
#else
|
||||
#define DWRITE_B0_1 # Pin B0 not supported on this MCU!
|
||||
#define DWRITE_B0_0 DWRITE_B0_1
|
||||
#endif
|
||||
#ifdef PB1
|
||||
#define DWRITE_B1_1 PORTB |= 0x02
|
||||
#define DWRITE_B1_0 PORTB &= 0xFD
|
||||
#else
|
||||
#define DWRITE_B1_1 # Pin B1 not supported on this MCU!
|
||||
#define DWRITE_B1_0 DWRITE_B1_1
|
||||
#endif
|
||||
#ifdef PB2
|
||||
#define DWRITE_B2_1 PORTB |= 0x04
|
||||
#define DWRITE_B2_0 PORTB &= 0xFB
|
||||
#else
|
||||
#define DWRITE_B2_1 # Pin B2 not supported on this MCU!
|
||||
#define DWRITE_B2_0 DWRITE_B2_1
|
||||
#endif
|
||||
#ifdef PB3
|
||||
#define DWRITE_B3_1 PORTB |= 0x08
|
||||
#define DWRITE_B3_0 PORTB &= 0xF7
|
||||
#else
|
||||
#define DWRITE_B3_1 # Pin B3 not supported on this MCU!
|
||||
#define DWRITE_B3_0 DWRITE_B3_1
|
||||
#endif
|
||||
#ifdef PB4
|
||||
#define DWRITE_B4_1 PORTB |= 0x10
|
||||
#define DWRITE_B4_0 PORTB &= 0xEF
|
||||
#else
|
||||
#define DWRITE_B4_1 # Pin B4 not supported on this MCU!
|
||||
#define DWRITE_B4_0 DWRITE_B4_1
|
||||
#endif
|
||||
#ifdef PB5
|
||||
#define DWRITE_B5_1 PORTB |= 0x20
|
||||
#define DWRITE_B5_0 PORTB &= 0xDF
|
||||
#else
|
||||
#define DWRITE_B5_1 # Pin B5 not supported on this MCU!
|
||||
#define DWRITE_B5_0 DWRITE_B5_1
|
||||
#endif
|
||||
#ifdef PB6
|
||||
#define DWRITE_B6_1 PORTB |= 0x40
|
||||
#define DWRITE_B6_0 PORTB &= 0xBF
|
||||
#else
|
||||
#define DWRITE_B6_1 # Pin B6 not supported on this MCU!
|
||||
#define DWRITE_B6_0 DWRITE_B6_1
|
||||
#endif
|
||||
#ifdef PB7
|
||||
#define DWRITE_B7_1 PORTB |= 0x80
|
||||
#define DWRITE_B7_0 PORTB &= 0x7F
|
||||
#else
|
||||
#define DWRITE_B7_1 # Pin B7 not supported on this MCU!
|
||||
#define DWRITE_B7_0 DWRITE_B7_1
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef PC0
|
||||
#define DWRITE_C0_1 PORTC |= 0x01
|
||||
#define DWRITE_C0_0 PORTC &= 0xFE
|
||||
#else
|
||||
#define DWRITE_C0_1 # Pin C0 not supported on this MCU!
|
||||
#define DWRITE_C0_0 DWRITE_C0_1
|
||||
#endif
|
||||
#ifdef PC1
|
||||
#define DWRITE_C1_1 PORTC |= 0x02
|
||||
#define DWRITE_C1_0 PORTC &= 0xFD
|
||||
#else
|
||||
#define DWRITE_C1_1 # Pin C1 not supported on this MCU!
|
||||
#define DWRITE_C1_0 DWRITE_C1_1
|
||||
#endif
|
||||
#ifdef PC2
|
||||
#define DWRITE_C2_1 PORTC |= 0x04
|
||||
#define DWRITE_C2_0 PORTC &= 0xFB
|
||||
#else
|
||||
#define DWRITE_C2_1 # Pin C2 not supported on this MCU!
|
||||
#define DWRITE_C2_0 DWRITE_C2_1
|
||||
#endif
|
||||
#ifdef PC3
|
||||
#define DWRITE_C3_1 PORTC |= 0x08
|
||||
#define DWRITE_C3_0 PORTC &= 0xF7
|
||||
#else
|
||||
#define DWRITE_C3_1 # Pin C3 not supported on this MCU!
|
||||
#define DWRITE_C3_0 DWRITE_C3_1
|
||||
#endif
|
||||
#ifdef PC4
|
||||
#define DWRITE_C4_1 PORTC |= 0x10
|
||||
#define DWRITE_C4_0 PORTC &= 0xEF
|
||||
#else
|
||||
#define DWRITE_C4_1 # Pin C4 not supported on this MCU!
|
||||
#define DWRITE_C4_0 DWRITE_C4_1
|
||||
#endif
|
||||
#ifdef PC5
|
||||
#define DWRITE_C5_1 PORTC |= 0x20
|
||||
#define DWRITE_C5_0 PORTC &= 0xDF
|
||||
#else
|
||||
#define DWRITE_C5_1 # Pin C5 not supported on this MCU!
|
||||
#define DWRITE_C5_0 DWRITE_C5_1
|
||||
#endif
|
||||
#ifdef PC6
|
||||
#define DWRITE_C6_1 PORTC |= 0x40
|
||||
#define DWRITE_C6_0 PORTC &= 0xBF
|
||||
#else
|
||||
#define DWRITE_C6_1 # Pin C6 not supported on this MCU!
|
||||
#define DWRITE_C6_0 DWRITE_C6_1
|
||||
#endif
|
||||
#ifdef PC7
|
||||
#define DWRITE_C7_1 PORTC |= 0x80
|
||||
#define DWRITE_C7_0 PORTC &= 0x7F
|
||||
#else
|
||||
#define DWRITE_C7_1 # Pin C7 not supported on this MCU!
|
||||
#define DWRITE_C7_0 DWRITE_C7_1
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef PD0
|
||||
#define DWRITE_D0_1 PORTD |= 0x01
|
||||
#define DWRITE_D0_0 PORTD &= 0xFE
|
||||
#else
|
||||
#define DWRITE_D0_1 # Pin D0 not supported on this MCU!
|
||||
#define DWRITE_D0_0 DWRITE_D0_1
|
||||
#endif
|
||||
#ifdef PD1
|
||||
#define DWRITE_D1_1 PORTD |= 0x02
|
||||
#define DWRITE_D1_0 PORTD &= 0xFD
|
||||
#else
|
||||
#define DWRITE_D1_1 # Pin D1 not supported on this MCU!
|
||||
#define DWRITE_D1_0 DWRITE_D1_1
|
||||
#endif
|
||||
#ifdef PD2
|
||||
#define DWRITE_D2_1 PORTD |= 0x04
|
||||
#define DWRITE_D2_0 PORTD &= 0xFB
|
||||
#else
|
||||
#define DWRITE_D2_1 # Pin D2 not supported on this MCU!
|
||||
#define DWRITE_D2_0 DWRITE_D2_1
|
||||
#endif
|
||||
#ifdef PD3
|
||||
#define DWRITE_D3_1 PORTD |= 0x08
|
||||
#define DWRITE_D3_0 PORTD &= 0xF7
|
||||
#else
|
||||
#define DWRITE_D3_1 # Pin D3 not supported on this MCU!
|
||||
#define DWRITE_D3_0 DWRITE_D3_1
|
||||
#endif
|
||||
#ifdef PD4
|
||||
#define DWRITE_D4_1 PORTD |= 0x10
|
||||
#define DWRITE_D4_0 PORTD &= 0xEF
|
||||
#else
|
||||
#define DWRITE_D4_1 # Pin D4 not supported on this MCU!
|
||||
#define DWRITE_D4_0 DWRITE_D4_1
|
||||
#endif
|
||||
#ifdef PD5
|
||||
#define DWRITE_D5_1 PORTD |= 0x20
|
||||
#define DWRITE_D5_0 PORTD &= 0xDF
|
||||
#else
|
||||
#define DWRITE_D5_1 # Pin D5 not supported on this MCU!
|
||||
#define DWRITE_D5_0 DWRITE_D5_1
|
||||
#endif
|
||||
#ifdef PD6
|
||||
#define DWRITE_D6_1 PORTD |= 0x40
|
||||
#define DWRITE_D6_0 PORTD &= 0xBF
|
||||
#else
|
||||
#define DWRITE_D6_1 # Pin D6 not supported on this MCU!
|
||||
#define DWRITE_D6_0 DWRITE_D6_1
|
||||
#endif
|
||||
#ifdef PD7
|
||||
#define DWRITE_D7_1 PORTD |= 0x80
|
||||
#define DWRITE_D7_0 PORTD &= 0x7F
|
||||
#else
|
||||
#define DWRITE_D7_1 # Pin D7 not supported on this MCU!
|
||||
#define DWRITE_D7_0 DWRITE_D7_1
|
||||
#endif
|
||||
|
||||
|
||||
#endif // PIO_DWRITE_H
|
78
pio/i2c/impl0.h
Normal file
78
pio/i2c/impl0.h
Normal file
|
@ -0,0 +1,78 @@
|
|||
/***
|
||||
* impl0.h
|
||||
* This file is part of the PIO library.
|
||||
* For license information see "pio.h" in the super parent directory.
|
||||
*/
|
||||
|
||||
#if !defined(PIOLIB) || PIOLIB < 100
|
||||
#error This file should be included directly. Use "pio.h" instead.
|
||||
#endif
|
||||
|
||||
#ifndef F_CPU
|
||||
#error F_CPU not defined!
|
||||
#endif
|
||||
|
||||
#ifndef F_I2C
|
||||
#ifndef PIO_DISABLE_I2C
|
||||
#warning F_I2C not defined, I2C disabled.
|
||||
#endif
|
||||
#else
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
// AVR TWI master transmitter status codes
|
||||
#define TWS_START 0x08
|
||||
#define TWS_REPEATED_START 0x10
|
||||
#define TWS_ADDR_ACK 0x18
|
||||
#define TWS_ADDR_NOT_ACK 0x20
|
||||
#define TWS_DATA_ACK 0x28
|
||||
#define TWS_DATA_NOT_ACK 0x30
|
||||
#define TWS_ARB_LOST 0x38
|
||||
|
||||
// functions
|
||||
void i2cInit(void);
|
||||
void i2cBeginTransmission(uint8_t);
|
||||
void i2cSend(uint8_t);
|
||||
void i2cEndTransmission(void);
|
||||
|
||||
// error function pointer
|
||||
void (*i2cError)(void) = NULL;
|
||||
|
||||
void i2cInit() {
|
||||
// i2c clock speed, see SCL frequency formula in datasheet
|
||||
uint16_t sp = F_CPU / F_I2C - 16;
|
||||
uint16_t bp = sp;
|
||||
while(sp > 510) {
|
||||
TWSR++;
|
||||
sp /= 4;
|
||||
}
|
||||
TWBR = bp / (1<<(2*(TWSR & 0x03)+1));
|
||||
}
|
||||
|
||||
void i2cBeginTransmission(uint8_t addr) {
|
||||
TWCR = _BV(TWEN) | _BV(TWINT) | _BV(TWSTA);
|
||||
while (!(TWCR & _BV(TWINT)));
|
||||
if((TWSR & 0xF8) != TWS_START)
|
||||
i2cError();
|
||||
|
||||
TWDR = (addr & 0xFE) << 1;
|
||||
TWCR = _BV(TWEN) | _BV(TWINT);
|
||||
while (!(TWCR & _BV(TWINT)));
|
||||
if((TWSR & 0xF8) != TWS_ADDR_ACK)
|
||||
i2cError();
|
||||
}
|
||||
|
||||
void i2cSend(uint8_t b) {
|
||||
TWDR = b;
|
||||
TWCR = _BV(TWEN) | _BV(TWINT);
|
||||
while (!(TWCR & _BV(TWINT)));
|
||||
if((TWSR & 0xF8) != TWS_DATA_ACK)
|
||||
i2cError();
|
||||
}
|
||||
|
||||
void i2cEndTransmission() {
|
||||
TWCR = _BV(TWEN) | _BV(TWINT) | _BV(TWSTO);
|
||||
while (TWCR & _BV(TWSTO));
|
||||
}
|
||||
|
||||
#endif
|
22
pio/mcus.h
Normal file
22
pio/mcus.h
Normal file
|
@ -0,0 +1,22 @@
|
|||
/***
|
||||
* mcus.h
|
||||
* This file is part of the PIO library.
|
||||
* For license information see "pio.h" in the parent directory.
|
||||
*/
|
||||
|
||||
#if !defined(PIOLIB) || PIOLIB < 100
|
||||
#error This file should be included directly. Use "pio.h" instead.
|
||||
#endif
|
||||
|
||||
#ifndef PIO_MCUS_H
|
||||
#define PIO_MCUS_H
|
||||
|
||||
#include "mcus/atmega328p.h"
|
||||
#include "mcus/atmega16.h"
|
||||
#include "mcus/atmega1284.h"
|
||||
|
||||
#ifndef MCU
|
||||
#error No compatible MCU header file found.
|
||||
#endif
|
||||
|
||||
#endif // PIO_MCUS_H
|
17
pio/mcus/atmega1284.h
Normal file
17
pio/mcus/atmega1284.h
Normal file
|
@ -0,0 +1,17 @@
|
|||
/***
|
||||
* atmega1284.h
|
||||
* This file is part of the PIO library.
|
||||
* For license information see "pio.h" in the super parent directory.
|
||||
*/
|
||||
|
||||
#if !defined(PIOLIB) || PIOLIB < 100
|
||||
#error This file should not be included directly. Use "pio.h" instead.
|
||||
#endif
|
||||
|
||||
#ifdef __AVR_ATmega1284__
|
||||
|
||||
#define MCU ATmega1284
|
||||
|
||||
#include "../i2c/impl0.h"
|
||||
|
||||
#endif
|
17
pio/mcus/atmega16.h
Normal file
17
pio/mcus/atmega16.h
Normal file
|
@ -0,0 +1,17 @@
|
|||
/***
|
||||
* atmega16.h
|
||||
* This file is part of the PIO library.
|
||||
* For license information see "pio.h" in the super parent directory.
|
||||
*/
|
||||
|
||||
#if !defined(PIOLIB) || PIOLIB < 100
|
||||
#error This file should not be included directly. Use "pio.h" instead.
|
||||
#endif
|
||||
|
||||
#ifdef __AVR_ATmega16__
|
||||
|
||||
#define MCU ATmega16
|
||||
|
||||
#include "../i2c/impl0.h"
|
||||
|
||||
#endif
|
14
pio/mcus/atmega328p.h
Normal file
14
pio/mcus/atmega328p.h
Normal file
|
@ -0,0 +1,14 @@
|
|||
/***
|
||||
* atmega328p.h
|
||||
* This file is part of the PIO library.
|
||||
* For license information see "pio.h" in the super parent directory.
|
||||
*/
|
||||
|
||||
#if !defined(PIOLIB) || PIOLIB < 100
|
||||
#error This file should not be included directly. Use "pio.h" instead.
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __AVR_ATmega328P__
|
||||
#error Not implemented!
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue