-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTwiPins.hpp
76 lines (62 loc) · 3.25 KB
/
TwiPins.hpp
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
#pragma once
//======================================================================
// TwiPins.hpp
//======================================================================
#include "MyAvr.hpp"
/*------------------------------------------------------------------------------
twi0 master/slave - basic/limited table for twim0 (not dual mode)
mega0/DA tiny0/1 tiny0/1 XX2 (8pin)
default SCL PA3 PB0 PA2
default SDA PA2 PB1 PA1
alt SCL PC3 PA2 --
alt SDA PC2 PA1 --
add new mcu's to this pin info table as needed
uncomment the set of pins that suits your mcu (instead of using a
series of ifdef's which get harder to manage as more mcu's are added)
add more as needed (can also add twi1 pins if needed)
portmux register names are not all the same, and the twi
bitfields in the portmux register also can be different
so will have to look these names up when creating a new
pair of pins
master/slave pins are the same for many mcu's, but is split so one can
use dual mode for those mcu's which are able to use a different set of
pins for master/slave
------------------------------------------------------------------------------*/
struct
TwiPinsT {
PORT_t* Mport; // master port- &PORTn
u8 MpinSCL; // 0-7
u8 MpinSCA; // 0-7
PORT_t* Sport; // slave port- &PORTn
u8 SpinSCL; // 0-7
u8 SpinSCA; // 0-7
volatile u8* pmux; // &PORTMUX.twi_register
u8 pmux_clrbm; // bitmask values to clear/set the appropriate twi bitfields in portmux to select a set of pins
u8 pmux_setbm; // the clrbm will be used to reset bitfield to default, the setbm will set the desired value
};
//------------------------------
// mega0
//------------------------------
// static const TwiPins //std
// TWI0_pins = { &PORTA, 3, 2, &PORTA, 3, 2, &PORTMUX_TWISPIROUTEA, PORTMUX_TWI0_gm, 0 };
// static const TwiPins //alt
// TWI0_pins = { &PORTC, 3, 2, &PORTC, 3, 2, &PORTMUX_TWISPIROUTEA, PORTMUX_TWI0_gm, PORTMUX_TWI0_ALT2_gc };
//------------------------------
// avrda
//------------------------------
// static const TwiPins //std
// TWI0_pins = { &PORTA, 3, 2, &PORTA, 3, 2, &PORTMUX_TWIROUTEA, PORTMUX_TWI0_gm, 0 };
// static const TwiPins //alt
// TWI0_pins = { &PORTC, 3, 2, &PORTC, 3, 2, &PORTMUX_TWIROUTEA, PORTMUX_TWI0_gm, PORTMUX_TWI0_ALT2_gc };
//------------------------------
// tiny0/1 w/alternate pins
//------------------------------
static const TwiPinsT //std
TWI0_pins = { &PORTB, 0, 1, &PORTB, 0, 1, &PORTMUX_CTRLB, PORTMUX_TWI0_bm, 0 };
// static const TwiPins //alt
// TWI0_pins = { &PORTA, 2, 1, &PORTA, 2, 1, &PORTMUX_CTRLB, PORTMUX_TWI0_bm, PORTMUX_TWI0_bm };
//------------------------------
// tiny0/1 no alternate pins
//------------------------------
// static const TwiPins //std only
// TWI0_std_pins = { &PORTB, 0, 1, &PORTB, 0, 1, 0, 0, 0 }; //pmux = 0 (no twi portmux)