Line 50... |
Line 50... |
*
|
*
|
* @return 0 if NEOLED was not synthesized, 1 if NEOLED is available.
|
* @return 0 if NEOLED was not synthesized, 1 if NEOLED is available.
|
**************************************************************************/
|
**************************************************************************/
|
int neorv32_neoled_available(void) {
|
int neorv32_neoled_available(void) {
|
|
|
if (SYSINFO_FEATURES & (1 << SYSINFO_FEATURES_IO_NEOLED)) {
|
if (NEORV32_SYSINFO.SOC & (1 << SYSINFO_SOC_IO_NEOLED)) {
|
return 1;
|
return 1;
|
}
|
}
|
else {
|
else {
|
return 0;
|
return 0;
|
}
|
}
|
}
|
}
|
|
|
|
|
/**********************************************************************//**
|
/**********************************************************************//**
|
* Enable and configure NEOLED controller. The NEOLED control register bits are listed in #NEORV32_NEOLED_CT_enum.
|
* Enable and configure NEOLED controller. The NEOLED control register bits are listed in #NEORV32_NEOLED_CTRL_enum.
|
* This function performs a "raw" configuration (just configuraing the according control register bit).
|
* This function performs a "raw" configuration (just configuraing the according control register bit).
|
*
|
*
|
* @param[in] prsc Clock prescaler select (0..7). See #NEORV32_CLOCK_PRSC_enum.
|
* @param[in] prsc Clock prescaler select (0..7). See #NEORV32_CLOCK_PRSC_enum.
|
* @param[in] t_total Number of pre-scaled clock ticks for total bit period (0..31).
|
* @param[in] t_total Number of pre-scaled clock ticks for total bit period (0..31).
|
* @param[in] t_high_zero Number of pre-scaled clock ticks to generate high-time for sending a '0' (0..31).
|
* @param[in] t_high_zero Number of pre-scaled clock ticks to generate high-time for sending a '0' (0..31).
|
* @param[in] t_high_one Number of pre-scaled clock ticks to generate high-time for sending a '1' (0..31).
|
* @param[in] t_high_one Number of pre-scaled clock ticks to generate high-time for sending a '1' (0..31).
|
**************************************************************************/
|
**************************************************************************/
|
void neorv32_neoled_setup(uint32_t prsc, uint32_t t_total, uint32_t t_high_zero, uint32_t t_high_one) {
|
void neorv32_neoled_setup(uint32_t prsc, uint32_t t_total, uint32_t t_high_zero, uint32_t t_high_one) {
|
|
|
NEOLED_CT = 0; // reset
|
NEORV32_NEOLED.CTRL = 0; // reset
|
|
|
// module enable
|
// module enable
|
uint32_t ct_enable = 1 << NEOLED_CT_EN;
|
uint32_t ct_enable = 1 << NEOLED_CTRL_EN;
|
|
|
// clock pre-scaler
|
// clock pre-scaler
|
uint32_t ct_prsc = (prsc & 0x7) << NEOLED_CT_PRSC0;
|
uint32_t ct_prsc = (prsc & 0x7) << NEOLED_CTRL_PRSC0;
|
|
|
// serial data output: total period length for one bit
|
// serial data output: total period length for one bit
|
uint32_t ct_t_total = (t_total & 0x1f) << NEOLED_CT_T_TOT_0;
|
uint32_t ct_t_total = (t_total & 0x1f) << NEOLED_CTRL_T_TOT_0;
|
|
|
// serial data output: high-time for sending a '0'
|
// serial data output: high-time for sending a '0'
|
uint32_t ct_t_zero = (t_high_zero & 0x1f) << NEOLED_CT_T_ZERO_H_0;
|
uint32_t ct_t_zero = (t_high_zero & 0x1f) << NEOLED_CTRL_T_ZERO_H_0;
|
|
|
// serial data output: high-time for sending a '1'
|
// serial data output: high-time for sending a '1'
|
uint32_t ct_t_one = (t_high_one & 0x1f) << NEOLED_CT_T_ONE_H_0;
|
uint32_t ct_t_one = (t_high_one & 0x1f) << NEOLED_CTRL_T_ONE_H_0;
|
|
|
// set new configuration
|
// set new configuration
|
NEOLED_CT = ct_enable | ct_prsc | ct_t_total | ct_t_zero | ct_t_one;
|
NEORV32_NEOLED.CTRL = ct_enable | ct_prsc | ct_t_total | ct_t_zero | ct_t_one;
|
}
|
}
|
|
|
|
|
/**********************************************************************//**
|
/**********************************************************************//**
|
* Configure NEOLED controller for using WS2812 LEDs (NeoPixel-compatible). This function computes
|
* Configure NEOLED controller for using WS2812 LEDs (NeoPixel-compatible). This function computes
|
Line 110... |
Line 110... |
|
|
// processor clock pre-scalers
|
// processor clock pre-scalers
|
const uint32_t CLK_PRSC_FACTOR_LUT[8] = {2, 4, 8, 64, 128, 1024, 2048, 4096};
|
const uint32_t CLK_PRSC_FACTOR_LUT[8] = {2, 4, 8, 64, 128, 1024, 2048, 4096};
|
|
|
// get base clock period in multiples of 0.5ns
|
// get base clock period in multiples of 0.5ns
|
uint32_t t_clock_x500ps = (2 * 1000 * 1000 * 1000) / SYSINFO_CLK;
|
uint32_t t_clock_x500ps = (2 * 1000 * 1000 * 1000) / NEORV32_SYSINFO.CLK;
|
|
|
// compute LED interface timing parameters
|
// compute LED interface timing parameters
|
uint32_t t_base = 0;
|
uint32_t t_base = 0;
|
uint32_t t_total = 0;
|
uint32_t t_total = 0;
|
uint32_t t_high_zero = 0;
|
uint32_t t_high_zero = 0;
|
Line 160... |
Line 160... |
*
|
*
|
* @param[in] mode 0 = 24-bit mode (RGB), 1 = 32-bit mode (RGBW)
|
* @param[in] mode 0 = 24-bit mode (RGB), 1 = 32-bit mode (RGBW)
|
**************************************************************************/
|
**************************************************************************/
|
void neorv32_neoled_set_mode(uint32_t mode) {
|
void neorv32_neoled_set_mode(uint32_t mode) {
|
|
|
uint32_t ctrl = NEOLED_CT;
|
uint32_t ctrl = NEORV32_NEOLED.CTRL;
|
ctrl &= ~(0b1 << NEOLED_CT_MODE); // clear current mode
|
ctrl &= ~(0b1 << NEOLED_CTRL_MODE); // clear current mode
|
ctrl |= ((mode & 1) << NEOLED_CT_MODE); // set new mode
|
ctrl |= ((mode & 1) << NEOLED_CTRL_MODE); // set new mode
|
NEOLED_CT = ctrl;
|
NEORV32_NEOLED.CTRL = ctrl;
|
}
|
}
|
|
|
|
|
/**********************************************************************//**
|
/**********************************************************************//**
|
* Send strobe command ("RESET") - blocking.
|
* Send strobe command ("RESET") - blocking.
|
**************************************************************************/
|
**************************************************************************/
|
void neorv32_neoled_strobe_blocking(void) {
|
void neorv32_neoled_strobe_blocking(void) {
|
|
|
while(1) { // wait for FIFO full flag to clear
|
while(1) { // wait for FIFO full flag to clear
|
if ((NEOLED_CT & (1 << NEOLED_CT_TX_FULL)) == 0) {
|
if ((NEORV32_NEOLED.CTRL & (1 << NEOLED_CTRL_TX_FULL)) == 0) {
|
break;
|
break;
|
}
|
}
|
}
|
}
|
|
|
neorv32_neoled_strobe_nonblocking();
|
neorv32_neoled_strobe_nonblocking();
|
Line 187... |
Line 187... |
/**********************************************************************//**
|
/**********************************************************************//**
|
* Send strobe command ("RESET") - non-blocking.
|
* Send strobe command ("RESET") - non-blocking.
|
**************************************************************************/
|
**************************************************************************/
|
void neorv32_neoled_strobe_nonblocking(void) {
|
void neorv32_neoled_strobe_nonblocking(void) {
|
|
|
const uint32_t mask = 1 << NEOLED_CT_STROBE; // strobe bit
|
const uint32_t mask = 1 << NEOLED_CTRL_STROBE; // strobe bit
|
uint32_t ctrl = NEOLED_CT;
|
uint32_t ctrl = NEORV32_NEOLED.CTRL;
|
|
|
NEOLED_CT = ctrl | mask; // set strobe bit
|
NEORV32_NEOLED.CTRL = ctrl | mask; // set strobe bit
|
NEOLED_DATA = 0; // send any data to trigger strobe command
|
NEORV32_NEOLED.DATA = 0; // send any data to trigger strobe command
|
NEOLED_CT = ctrl & (~mask); // clear strobe bit
|
NEORV32_NEOLED.CTRL = ctrl & (~mask); // clear strobe bit
|
}
|
}
|
|
|
|
|
/**********************************************************************//**
|
/**********************************************************************//**
|
* Enable NEOLED controller.
|
* Enable NEOLED controller.
|
**************************************************************************/
|
**************************************************************************/
|
void neorv32_neoled_enable(void) {
|
void neorv32_neoled_enable(void) {
|
|
|
NEOLED_CT |= ((uint32_t)(1 << NEOLED_CT_EN));
|
NEORV32_NEOLED.CTRL |= ((uint32_t)(1 << NEOLED_CTRL_EN));
|
}
|
}
|
|
|
|
|
/**********************************************************************//**
|
/**********************************************************************//**
|
* Disable NEOLED controller.
|
* Disable NEOLED controller.
|
**************************************************************************/
|
**************************************************************************/
|
void neorv32_neoled_disable(void) {
|
void neorv32_neoled_disable(void) {
|
|
|
NEOLED_CT &= ~((uint32_t)(1 << NEOLED_CT_EN));
|
NEORV32_NEOLED.CTRL &= ~((uint32_t)(1 << NEOLED_CTRL_EN));
|
}
|
}
|
|
|
|
|
/**********************************************************************//**
|
/**********************************************************************//**
|
* Send single RGB(W) data word to NEOLED module (blocking).
|
* Send single RGB(W) data word to NEOLED module (blocking).
|
Line 224... |
Line 224... |
* @param[in] data LSB-aligned 24-bit RGB or 32-bit RGBW data
|
* @param[in] data LSB-aligned 24-bit RGB or 32-bit RGBW data
|
**************************************************************************/
|
**************************************************************************/
|
void neorv32_neoled_write_blocking(uint32_t data) {
|
void neorv32_neoled_write_blocking(uint32_t data) {
|
|
|
while(1) { // wait for FIFO full flag to clear
|
while(1) { // wait for FIFO full flag to clear
|
if ((NEOLED_CT & (1 << NEOLED_CT_TX_FULL)) == 0) {
|
if ((NEORV32_NEOLED.CTRL & (1 << NEOLED_CTRL_TX_FULL)) == 0) {
|
break;
|
break;
|
}
|
}
|
}
|
}
|
|
|
neorv32_neoled_write_nonblocking(data); // send new LED data
|
neorv32_neoled_write_nonblocking(data); // send new LED data
|
Line 240... |
Line 240... |
*
|
*
|
* @return Number of entries in NEOLED TX buffer.
|
* @return Number of entries in NEOLED TX buffer.
|
**************************************************************************/
|
**************************************************************************/
|
uint32_t neorv32_neoled_get_buffer_size(void) {
|
uint32_t neorv32_neoled_get_buffer_size(void) {
|
|
|
uint32_t tmp = NEOLED_CT;
|
uint32_t tmp = NEORV32_NEOLED.CTRL;
|
tmp = tmp >> NEOLED_CT_BUFS_0;
|
tmp = tmp >> NEOLED_CTRL_BUFS_0;
|
tmp = tmp & 0xf; // isolate buffer size bits
|
tmp = tmp & 0xf; // isolate buffer size bits
|
|
|
return (1 << tmp); // num entries = pow(2, buffer size flags)
|
return (1 << tmp); // num entries = pow(2, buffer size flags)
|
}
|
}
|
|
|
No newline at end of file
|
No newline at end of file
|