ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
ra8_glcdc_gamma.c File Reference

GLCDC piecewise-linear gamma correction driver. More...

#include <stdint.h>
#include "ra8_attributes.h"
#include "ra8_check.h"
#include "ra8_err.h"
#include "ra8_glcdc.h"
#include "ra8_glcdc_regs.h"
#include "ra8_log.h"
Include dependency graph for ra8_glcdc_gamma.c:

Go to the source code of this file.

Enumerations

enum  ra8_glcdc_gam_reg_count_t : uint8_t {
  k_ra8_glcdc_gam_reg_count = 8U ,
  k_ra8_glcdc_gam_pair_step = 2U
}
 Number of LUT and AREA registers per gamma channel block. More...

Functions

static void internal_write_lut (volatile ra8_glcdc_gam_t *gam, const uint16_t *gain)
 Write one channel's 8 LUT (gain-pair) registers.
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_err_t ra8_glcdc_gamma_enable (bool enable)
 Enable or disable the GLCDC gamma correction pipeline.

Variables

static const char * s_tag = "GLCDC"

Detailed Description

GLCDC piecewise-linear gamma correction driver.

Tag
[Ring 3 / HAL] {World: NS}

Implements per-channel gamma correction for the RA8D2 GLCDC output pipeline. The hardware provides three independent 16-segment piecewise-linear correction blocks (GAM[0]=R, GAM[1]=G, GAM[2]=B). Each block exposes eight 32-bit LUT registers (two 11-bit gain coefficients each) and eight 32-bit AREA registers (two 10-bit boundary thresholds each), together defining a 16-point correction curve per channel. The global enable/disable switch lives in the shared OUT block at k_ra8_glcdc_off_out_gamsw.

Every register access is preceded by a HUM Ch 63 citation.

Definition in file ra8_glcdc_gamma.c.

Enumeration Type Documentation

◆ ra8_glcdc_gam_reg_count_t

enum ra8_glcdc_gam_reg_count_t : uint8_t

Number of LUT and AREA registers per gamma channel block.

HUM Ch 63 "GAMx_LUTn Gamma Correction LUT Register" p 3790 lists LUT[0..7] (eight registers, two gains per register = 16 gain values). HUM Ch 63 "GAMx_AREAn Gamma Correction Area Register" p 3793 lists AREA[0..7] (eight registers, two thresholds per register = 16 values). k_ra8_glcdc_gamma_lut_depth / 2 = 8 gives the register count.

Enumerator
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).

Definition at line 51 of file ra8_glcdc_gamma.c.

Function Documentation

◆ internal_write_area()

void internal_write_area ( volatile ra8_glcdc_gam_t * gam,
const uint16_t * threshold )
static

Write one channel's 8 AREA (threshold-pair) registers.

Packs successive pairs from threshold[] into GAMx_AREA[0..7]. The high 16-bit field (TH1, bits[25:16]) receives threshold[2*i]; the low 10-bit field (TH2, bits[9:0]) receives threshold[2*i+1].

Parameters
[in]gamPointer to the channel's gamma register block.
[in]thresholdArray of k_ra8_glcdc_gamma_lut_depth 10-bit threshold values.
Precondition
gam != nullptr (caller guarantees).
threshold != nullptr (caller guarantees).
Postcondition
All 8 GAMx_AREAn registers hold the packed threshold pairs.
All 16 threshold[] entries (indices 0..15) are consumed; no register outside GAMx_AREA[0..7] is written.
Note
Not thread-safe.
Since
0.1.0

Definition at line 113 of file ra8_glcdc_gamma.c.

References ra8_glcdc_gam_t::AREA, k_ra8_glcdc_gam_area_th_h_shift, k_ra8_glcdc_gam_area_th_l_mask, k_ra8_glcdc_gam_pair_step, and k_ra8_glcdc_gam_reg_count.

Referenced by ra8_glcdc_set_gamma().

◆ internal_write_lut()

void internal_write_lut ( volatile ra8_glcdc_gam_t * gam,
const uint16_t * gain )
static

Write one channel's 8 LUT (gain-pair) registers.

Packs successive pairs from gain[] into GAMx_LUT[0..7]. The high 16-bit field (GAIN0, bits[26:16]) receives gain[2*i]; the low 11-bit field (GAIN1, bits[10:0]) receives gain[2*i+1].

Parameters
[in]gamPointer to the channel's gamma register block.
[in]gainArray of k_ra8_glcdc_gamma_lut_depth 11-bit gain values.
Precondition
gam != nullptr (caller guarantees).
gain != nullptr (caller guarantees).
Postcondition
All 8 GAMx_LUTn registers hold the packed gain pairs.
All 16 gain[] entries (indices 0..15) are consumed; no register outside GAMx_LUT[0..7] is written.
Note
Not thread-safe.
Since
0.1.0

Definition at line 81 of file ra8_glcdc_gamma.c.

References k_ra8_glcdc_gam_lut_gain_h_shift, k_ra8_glcdc_gam_lut_gain_l_mask, k_ra8_glcdc_gam_pair_step, k_ra8_glcdc_gam_reg_count, and ra8_glcdc_gam_t::LUT.

Referenced by ra8_glcdc_set_gamma().

◆ ra8_glcdc_gamma_enable()

ra8_err_t ra8_glcdc_gamma_enable ( bool enable)
nodiscard

Enable or disable the GLCDC gamma correction pipeline.

Writes the GAMSW.GAMON bit (bit 0) in the output-control block, which gates the piecewise-linear correction circuit for all three colour channels. Call after programming all three channel tables with ra8_glcdc_set_gamma().

Parameters
[in]enabletrue to activate gamma correction; false to bypass it.
Returns
ra8_err_t error code.
Return values
k_ra8_okGAMSW register updated.
k_ra8_err_null_ptrGAMSW register address could not be resolved (should not occur in normal operation).
Precondition
GLCDC has been initialised via ra8_glcdc_init().
All three channel tables have been written via ra8_glcdc_set_gamma() when enabling.
Postcondition
OUT.GAMSW.GAMON == (enable ? 1 : 0).
The gamma pipeline state is visible on the next active pixel.
Note
Not thread-safe; caller must serialise access to GLCDC registers.
See also
ra8_glcdc_set_gamma() Programme individual channel tables.
Since
0.1.0
HUM:
Ch 63 "OUT_GAMSW Gamma Correction Block Switch Register" p 3789.

Definition at line 155 of file ra8_glcdc_gamma.c.

References k_ra8_glcdc_gamsw_gamon, k_ra8_glcdc_off_out_gamsw, k_ra8_ok, RA8_CHECK_NULL_PTR, ra8_glcdc_reg32(), ra8_log_info_val, and s_tag.

◆ ra8_glcdc_set_gamma()

ra8_err_t ra8_glcdc_set_gamma ( ra8_glcdc_color_channel_t channel,
const uint16_t * gain,
const uint16_t * threshold,
uint8_t count )
nodiscard

Programme the piecewise-linear gamma correction table for one channel.

Writes the 8 GAMx_LUTn gain-pair registers and the 8 GAMx_AREAn threshold-pair registers for the selected colour channel. Each LUT register packs two 11-bit gain coefficients (GAIN0 in bits[26:16], GAIN1 in bits[10:0]); each AREA register packs two 10-bit boundary values (TH1 in bits[25:16], TH2 in bits[9:0]). Call ra8_glcdc_gamma_enable(true) after programming all three channels to activate the correction pipeline.

Parameters
[in]channelColour channel to program (R, G, or B).
[in]gainArray of k_ra8_glcdc_gamma_lut_depth 11-bit gain values (0..2047). gain[0] corresponds to GAIN0 of LUT[0].
[in]thresholdArray of k_ra8_glcdc_gamma_lut_depth 10-bit boundary values (0..1023). threshold[0] corresponds to TH1 of AREA[0].
[in]countMust equal k_ra8_glcdc_gamma_lut_depth (16); enforced.
Returns
ra8_err_t error code.
Return values
k_ra8_okLUT and AREA registers written.
k_ra8_err_null_ptrgain or threshold is NULL.
k_ra8_err_invalid_argchannel >= k_ra8_glcdc_ch_count, or count != k_ra8_glcdc_gamma_lut_depth.
Precondition
GLCDC has been initialised via ra8_glcdc_init().
gain and threshold point to arrays of at least count elements.
Postcondition
All 8 GAMx_LUTn registers hold the packed gain pairs.
All 8 GAMx_AREAn registers hold the packed threshold pairs.
Note
Not thread-safe; caller must serialise access to GLCDC registers.
See also
ra8_glcdc_gamma_enable() Activate or deactivate the pipeline.
Since
0.1.0
HUM:
Ch 63 "GAMx_LUTn Gamma Correction LUT Register" p 3790. Ch 63 "GAMx_AREAn Gamma Correction Area Register" p 3793.

Definition at line 131 of file ra8_glcdc_gamma.c.

References internal_write_area(), internal_write_lut(), k_ra8_err_invalid_arg, k_ra8_glcdc_ch_count, k_ra8_glcdc_gamma_lut_depth, k_ra8_ok, RA8_CHECK_NULL_PTR, ra8_glcdc_gam_regs(), ra8_log_info_val, and s_tag.

Variable Documentation

◆ s_tag

const char* s_tag = "GLCDC"
static

Definition at line 33 of file ra8_glcdc_gamma.c.