SSD1306 OLED display driver  1.6.99
This library is developed to control SSD1306/SSD1331/SSD1351/IL9163/PCD8554 RGB i2c/spi LED displays
gpio.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 #if defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)
30  #define G0_DIR DDRB
31  #define G0_PORT PORTB
32  #define G1_DIR DDRB
33  #define G1_PORT PORTB
34  #define G2_DIR DDRB
35  #define G2_PORT PORTB
36 #elif defined(__AVR_ATmega328P__)
37  #define G0_DIR DDRD
38  #define G0_PORT PORTD
39  #define G1_DIR DDRB
40  #define G1_PORT PORTB
41  #define G2_DIR DDRC
42  #define G2_PORT PORTC
43 #else
44  static uint8_t s_stub;
45  #define G0_DIR s_stub
46  #define G0_PORT s_stub
47  #define G1_DIR s_stub
48  #define G1_PORT s_stub
49  #define G2_DIR s_stub
50  #define G2_PORT s_stub
51 #endif
52 
53 void digitalWrite(int pin, int level)
54 {
55  uint8_t mask = (1<<(pin & 0x7));
56  if (pin<8)
57  {
58  if (level == HIGH) G0_PORT |= mask; else G0_PORT &= ~mask;
59  }
60  else if (pin<16)
61  {
62  if (level == HIGH) G1_PORT |= mask; else G1_PORT &= ~mask;
63  }
64  else
65  {
66  if (level == HIGH) G2_PORT |= mask; else G2_PORT &= ~mask;
67  }
68 }
69 
70 void pinMode(int pin, int mode)
71 {
72  uint8_t mask = (1<<(pin & 0x7));
73  if (pin<8)
74  {
75  if (mode == OUTPUT) G0_DIR |= mask; else G0_DIR &= ~mask;
76  }
77  else if (pin<16)
78  {
79  if (mode == OUTPUT) G1_DIR |= mask; else G1_DIR &= ~mask;
80  }
81  else
82  {
83  if (mode == OUTPUT) G2_DIR |= mask; else G2_DIR &= ~mask;
84  }
85 };
86 
87 #endif
88