SSD1306 OLED display driver 1.7.8 This library is developed to control SSD1306/SSD1331/SSD1351/IL9163/PCD8554 RGB i2c/spi LED displays

platform.c
1 /*
2 MIT License
3
4 Copyright (c) 2018, Alexey Dynda
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to deal
8 in the Software without restriction, including without limitation the rights
9 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in all
14 copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 SOFTWARE.
23 */
24
25 #include "ssd1306_hal/io.h"
26
27 #if defined(__AVR__) && !defined(ARDUINO)
28
29 void delay(unsigned long ms)
30 {
31 while (ms--)
32 {
33 _delay_ms(1);
34 }
35 }
36
37 #if defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)
38 #define G0_DIR DDRB
39 #define G0_PORT PORTB
40 #define G1_DIR DDRB
41 #define G1_PORT PORTB
42 #define G2_DIR DDRB
43 #define G2_PORT PORTB
44 #elif defined(__AVR_ATmega328P__)
45 #define G0_DIR DDRD
46 #define G0_PORT PORTD
47 #define G1_DIR DDRB
48 #define G1_PORT PORTB
49 #define G2_DIR DDRC
50 #define G2_PORT PORTC
51 #else
52 static uint8_t s_stub;
53 #define G0_DIR s_stub
54 #define G0_PORT s_stub
55 #define G1_DIR s_stub
56 #define G1_PORT s_stub
57 #define G2_DIR s_stub
58 #define G2_PORT s_stub
59 #endif
60
61 void digitalWrite(int pin, int level)
62 {
63 uint8_t mask = (1<<(pin & 0x7));
64 if (pin<8)
65 {
66 if (level == HIGH) G0_PORT |= mask; else G0_PORT &= ~mask;
67 }
68 else if (pin<16)
69 {
70 if (level == HIGH) G1_PORT |= mask; else G1_PORT &= ~mask;
71 }
72 else
73 {
74 if (level == HIGH) G2_PORT |= mask; else G2_PORT &= ~mask;
75 }
76 }
77
78 void pinMode(int pin, int mode)
79 {
80 uint8_t mask = (1<<(pin & 0x7));
81 if (pin<8)
82 {
83 if (mode == OUTPUT) G0_DIR |= mask; else G0_DIR &= ~mask;
84 }
85 else if (pin<16)
86 {
87 if (mode == OUTPUT) G1_DIR |= mask; else G1_DIR &= ~mask;
88 }
89 else
90 {
91 if (mode == OUTPUT) G2_DIR |= mask; else G2_DIR &= ~mask;
92 }
93 };
94
95 #endif
96
io.h