ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
ra8_glcdc_gamma.c
Go to the documentation of this file.
1
23
24#include <stdint.h>
25
26#include "ra8_attributes.h"
27#include "ra8_check.h"
28#include "ra8_err.h"
29#include "ra8_glcdc.h"
30#include "ra8_glcdc_regs.h"
31#include "ra8_log.h"
32
33static const char* s_tag = "GLCDC";
34
35/* =============================================================================
36 * Module-private constants
37 * =============================================================================
38 */
39
55
56/* =============================================================================
57 * Internal helpers (one per loop body to stay inside the 60-line limit)
58 * =============================================================================
59 */
60
81static void internal_write_lut(volatile ra8_glcdc_gam_t* gam, const uint16_t* gain)
82{
83 for (uint8_t i = 0U; i < (uint8_t)k_ra8_glcdc_gam_reg_count; i++) {
84 const uint8_t hi_idx = (uint8_t)(i * (uint8_t)k_ra8_glcdc_gam_pair_step);
85 const uint8_t lo_idx = (uint8_t)(hi_idx + 1U);
86 const uint32_t packed = ((uint32_t)gain[hi_idx] << k_ra8_glcdc_gam_lut_gain_h_shift) |
87 ((uint32_t)gain[lo_idx] & (uint32_t)k_ra8_glcdc_gam_lut_gain_l_mask);
88 /* HUM Ch 63 "GAMx_LUTn Gamma Correction LUT Register" p 3790 */
89 gam->LUT[i] = packed;
90 }
91}
92
113static void internal_write_area(volatile ra8_glcdc_gam_t* gam, const uint16_t* threshold)
114{
115 for (uint8_t i = 0U; i < (uint8_t)k_ra8_glcdc_gam_reg_count; i++) {
116 const uint8_t hi_idx = (uint8_t)(i * (uint8_t)k_ra8_glcdc_gam_pair_step);
117 const uint8_t lo_idx = (uint8_t)(hi_idx + 1U);
118 const uint32_t packed =
119 ((uint32_t)threshold[hi_idx] << k_ra8_glcdc_gam_area_th_h_shift) |
120 ((uint32_t)threshold[lo_idx] & (uint32_t)k_ra8_glcdc_gam_area_th_l_mask);
121 /* HUM Ch 63 "GAMx_AREAn Gamma Correction Area Register" p 3793 */
122 gam->AREA[i] = packed;
123 }
124}
125
126/* =============================================================================
127 * Public API
128 * =============================================================================
129 */
130
132 const uint16_t* gain,
133 const uint16_t* threshold,
134 uint8_t count)
135{
136 RA8_CHECK_NULL_PTR(gain, s_tag, "gain must not be nullptr");
137 RA8_CHECK_NULL_PTR(threshold, s_tag, "threshold must not be nullptr");
138 if ((uint8_t)channel >= (uint8_t)k_ra8_glcdc_ch_count) {
140 }
141 if (count != (uint8_t)k_ra8_glcdc_gamma_lut_depth) {
143 }
144
145 volatile ra8_glcdc_gam_t* gam = ra8_glcdc_gam_regs((uint8_t)channel);
146 RA8_CHECK_NULL_PTR(gam, s_tag, "gamma register block inaccessible");
147
148 internal_write_lut(gam, gain);
149 internal_write_area(gam, threshold);
150
151 ra8_log_info_val(s_tag, "set_gamma channel", (uint32_t)channel);
152 return k_ra8_ok;
153}
154
156{
157 volatile uint32_t* const reg = ra8_glcdc_reg32(k_ra8_glcdc_off_out_gamsw);
158 RA8_CHECK_NULL_PTR(reg, s_tag, "GAMSW register inaccessible");
159
160 /* HUM Ch 63 "OUT_GAMSW Gamma Correction Block Switch Register" p 3789 */
161 if (enable) {
162 *reg = (uint32_t)k_ra8_glcdc_gamsw_gamon;
163 } else {
164 *reg = 0U;
165 }
166
167 ra8_log_info_val(s_tag, "gamma_enable", enable ? 1UL : 0UL);
168 return k_ra8_ok;
169}
static const char * s_tag
Logging / check tag.
Definition ra8_app.c:17
Annotation-attribute framework macros for ra8-firmware.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
Validation and Error-Checking Macros for ra8-firmware.
#define RA8_CHECK_NULL_PTR(ptr, tag, message)
Reject nullptr pointer, returning k_ra8_err_null_ptr.
Definition ra8_check.h:243
Error Code Definitions for ra8-firmware.
@ k_ra8_err_invalid_arg
Invalid function argument.
Definition ra8_err.h:152
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
Definition ra8_err.h:119
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
Definition ra8_err.h:546
Graphics LCD Controller driver (two-layer with alpha blending).
ra8_glcdc_color_channel_t
Selector for the three GLCDC gamma colour channels.
Definition ra8_glcdc.h:451
@ k_ra8_glcdc_ch_count
Number of colour channels (sentinel).
Definition ra8_glcdc.h:455
@ k_ra8_glcdc_gamma_lut_depth
16 segments (8 LUT regs x 2 gains).
Definition ra8_glcdc.h:474
ra8_err_t ra8_glcdc_gamma_enable(bool enable)
Enable or disable the GLCDC gamma correction pipeline.
static void internal_write_area(volatile ra8_glcdc_gam_t *gam, const uint16_t *threshold)
Write one channel's 8 AREA (threshold-pair) registers.
ra8_err_t ra8_glcdc_set_gamma(ra8_glcdc_color_channel_t channel, const uint16_t *gain, const uint16_t *threshold, uint8_t count)
Programme the piecewise-linear gamma correction table for one channel.
ra8_glcdc_gam_reg_count_t
Number of LUT and AREA registers per gamma channel block.
@ k_ra8_glcdc_gam_reg_count
LUT/AREA registers per channel (depth/2).
@ k_ra8_glcdc_gam_pair_step
Entries packed per register (2 per reg).
static void internal_write_lut(volatile ra8_glcdc_gam_t *gam, const uint16_t *gain)
Write one channel's 8 LUT (gain-pair) registers.
Graphics LCD Controller (GLCDC) register layout for the RA8D2.
static volatile ra8_glcdc_gam_t * ra8_glcdc_gam_regs(uint8_t channel_idx)
Return a volatile pointer to a per-channel gamma register block.
@ k_ra8_glcdc_off_out_gamsw
OUT.GAMSW: gamma enable switch.
static volatile uint32_t * ra8_glcdc_reg32(ra8_glcdc_block_off_t offset)
Pointer to a 32-bit register inside the GLCDC block.
@ k_ra8_glcdc_gamsw_gamon
GAMSW.GAMON: global gamma enable.
@ k_ra8_glcdc_gam_area_th_h_shift
AREA TH1 bit-shift.
@ k_ra8_glcdc_gam_area_th_l_mask
AREA TH2 10-bit mask.
@ k_ra8_glcdc_gam_lut_gain_l_mask
LUT GAIN1 11-bit mask.
@ k_ra8_glcdc_gam_lut_gain_h_shift
LUT GAIN0 bit-shift.
Lightweight Logging Interface for ra8-firmware.
#define ra8_log_info_val(tag, message, value)
RA8 log info val.
Definition ra8_log.h:366
Per-channel gamma correction register block (HUM Ch 63 p 3789-3793).
volatile uint32_t LUT[8]
Gain-pair registers LUT[0..7].
volatile uint32_t AREA[8]
Threshold-pair registers AREA[0..7].