2 * This file is part of Cleanflight and Betaflight.
4 * Cleanflight and Betaflight are free software. You can redistribute
5 * this software and/or modify this software under the terms of the
6 * GNU General Public License as published by the Free Software
7 * Foundation, either version 3 of the License, or (at your option)
10 * Cleanflight and Betaflight are distributed in the hope that they
11 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
12 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this software.
18 * If not, see <http://www.gnu.org/licenses/>.
26 #include "common/utils.h"
28 #include "drivers/display.h"
29 #include "drivers/display_ug2864hsweg01.h"
31 static displayPort_t oledDisplayPort
;
33 static int oledGrab(displayPort_t
*displayPort
)
39 static int oledRelease(displayPort_t
*displayPort
)
45 static int oledClearScreen(displayPort_t
*displayPort
)
47 i2c_OLED_clear_display_quick(displayPort
->device
);
51 static bool oledDrawScreen(displayPort_t
*displayPort
)
57 static int oledScreenSize(const displayPort_t
*displayPort
)
59 return displayPort
->rows
* displayPort
->cols
;
62 static int oledWriteString(displayPort_t
*displayPort
, uint8_t x
, uint8_t y
, uint8_t attr
, const char *s
)
66 i2c_OLED_set_xy(displayPort
->device
, x
, y
);
67 i2c_OLED_send_string(displayPort
->device
, s
);
71 static int oledWriteChar(displayPort_t
*displayPort
, uint8_t x
, uint8_t y
, uint8_t attr
, uint8_t c
)
75 i2c_OLED_set_xy(displayPort
->device
, x
, y
);
76 i2c_OLED_send_char(displayPort
->device
, c
);
80 static bool oledIsTransferInProgress(const displayPort_t
*displayPort
)
86 static bool oledIsSynced(const displayPort_t
*displayPort
)
92 static int oledHeartbeat(displayPort_t
*displayPort
)
98 static void oledRedraw(displayPort_t
*displayPort
)
103 static uint32_t oledTxBytesFree(const displayPort_t
*displayPort
)
109 static const displayPortVTable_t oledVTable
= {
111 .release
= oledRelease
,
112 .clearScreen
= oledClearScreen
,
113 .drawScreen
= oledDrawScreen
,
114 .screenSize
= oledScreenSize
,
115 .writeString
= oledWriteString
,
116 .writeChar
= oledWriteChar
,
117 .isTransferInProgress
= oledIsTransferInProgress
,
118 .heartbeat
= oledHeartbeat
,
119 .redraw
= oledRedraw
,
120 .isSynced
= oledIsSynced
,
121 .txBytesFree
= oledTxBytesFree
,
122 .layerSupported
= NULL
,
127 displayPort_t
*displayPortOledInit(void *device
)
129 oledDisplayPort
.device
= device
;
130 displayInit(&oledDisplayPort
, &oledVTable
, DISPLAYPORT_DEVICE_TYPE_OLED
);
131 oledDisplayPort
.rows
= SCREEN_CHARACTER_ROW_COUNT
;
132 oledDisplayPort
.cols
= SCREEN_CHARACTER_COLUMN_COUNT
;
133 return &oledDisplayPort
;