Skip to content

Commit 860506d

Browse files
committed
lpc1788 added next base address update interrupt support for the lcd controller
1 parent 3709b6c commit 860506d

1 file changed

Lines changed: 43 additions & 1 deletion

File tree

targets/core/nxp/lpc178x/lcd.hpp

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ namespace klib::core::lpc178x::io {
2020
template <typename Lcd, graphics::mode Mode = graphics::mode::rgb565>
2121
class lcd {
2222
public:
23+
// using for the array of callbacks
24+
using interrupt_callback = void(*)();
25+
2326
/**
2427
* @brief The clock source for the LCD clock
2528
*
@@ -88,6 +91,9 @@ namespace klib::core::lpc178x::io {
8891
"Invalid graphics mode for controller or not supported"
8992
);
9093

94+
// pointer to a callback
95+
static inline interrupt_callback lcd_callback = nullptr;
96+
9197
constexpr static uint8_t graphics_to_raw() {
9298
// get the bits the mode supports
9399
constexpr static uint32_t bits = graphics::detail::pixel_conversion<Mode>::bits;
@@ -106,13 +112,30 @@ namespace klib::core::lpc178x::io {
106112
}
107113
}
108114

115+
static void interrupt_handler() {
116+
// get the mask and status
117+
const uint32_t mask = Lcd::port->INTMSK;
118+
const uint32_t status = Lcd::port->INTRAW;
119+
120+
// get the masked status
121+
const uint32_t masked = status & mask;
122+
123+
// clear the interrupt bits
124+
Lcd::port->INTCLR = masked;
125+
126+
// call the callback
127+
if (lcd_callback) {
128+
lcd_callback();
129+
}
130+
}
131+
109132
public:
110133
template <
111134
std::endian ByteEndian = std::endian::native,
112135
std::endian PixelEndian = std::endian::native,
113136
clock_source Source = clock_source::cclk
114137
>
115-
static bool init(const timing_config& config, const io_polarity& polarity) {
138+
static bool init(const timing_config& config, const io_polarity& polarity, const interrupt_callback& callback = nullptr) {
116139
// check for correct values in the active height and width fields
117140
if (config.active_width < 16 || config.active_width > 1024 || !config.hsync) {
118141
return false;
@@ -229,6 +252,25 @@ namespace klib::core::lpc178x::io {
229252
((config.vbp & 0xff) << 24)
230253
);
231254

255+
// check if we need any interrupt or not
256+
if (callback) {
257+
// register our handler if we have a callback
258+
lcd_callback = callback;
259+
target::irq::register_irq<Lcd::interrupt_id>(interrupt_handler);
260+
261+
// enable the interrupt
262+
target::enable_irq<Lcd::interrupt_id>();
263+
264+
// enable the lnbuin interrupt
265+
Lcd::port->INTMSK = 0x1 << 2;
266+
}
267+
else {
268+
target::disable_irq<Lcd::interrupt_id>();
269+
270+
// clear all the enabled interrupts
271+
Lcd::port->INTMSK = 0;
272+
}
273+
232274
// set the control register
233275
Lcd::port->CTRL = (
234276
(0x1 << 0) |

0 commit comments

Comments
 (0)