Kameleon STM32L4 library reference

Table of Contents

Joystick (kamami_l496_joy.h)

Library for reading joystick switches with or without debouncing.
void joy_init(void)
Description:
Initializes all peripherals required for joystick. Must be called before other joy_ functions.

uint16_t joy_update(void)
Description:
If you want to read joystick switches states with debounce then this function should be called by timer interrupt with constant interval (e.g. SysTick). If timer interrupt frequency is not equal to 1000Hz then you have to define the frequency as JOYTIM_FREQ constant.

Return value:

Function returns joystick switches states as a combination of JOY_RIGHT, JOY_LEFT, JOY_DOWN, JOY_UP and JOY_OK constants.

uint16_t joy_get_state(void)
Description:
Function returns states of joystick switches after debouncing.

Return value:

Function returns joystick switches states as a combination of JOY_RIGHT, JOY_LEFT, JOY_DOWN, JOY_UP and JOY_OK constants.

uint16_t joy_get_raw_state(void)
Description:
Function returns states of joystick switches without debouncing.

Return value:

Function returns joystick switches states as a combination of JOY_RIGHT, JOY_LEFT, JOY_DOWN, JOY_UP and JOY_OK constants.

LEDs (kamami_l496_led.h)

Library controls 8 LEDs available on Kameleon Board. You can turn on, turn off and toggle single LED or a group of LEDs.
void led_init(void)
Description:
Initializes all GPIOs necessary to control LEDs. Must be called before other led_ functions.

void led_on(uint8_t led_num)
Description:
Function turns on single LED.

Parameters:

  • led_num – Number of LED (0-7).

void led_off(uint8_t led_num)
Description:
Function turns off single LED.

Parameters:

  • led_num – Number of LED (0-7).

void led_toggle(uint8_t led_num)
Description:
Function toggles single LED.

Parameters:

  • led_num – Number of LED (0-7).

void led_set_mul(uint8_t led_msk)
Description:
Function sets state of all LEDs.

Parameters:

  • led_msk – Every bit controls single LED (0 – LED is off, 1 – LED is on).

void led_on_mul(uint8_t led_msk)
Description:
Function turns on multiple LEDs selected by led_msk parameter.

Parameters:

  • led_msk – Mask determines which LEDs are turned on.

void led_off_mul(uint8_t led_msk)
Description:
Function turns off multiple LEDs selected by led_msk parameter.

Parameters:

  • led_msk – Mask determines which LEDs are turned off.

void led_toggle_mul(uint8_t led_msk)
Description:
Function toggles multiple LEDs selected by led_msk parameter.

Parameters:

  • led_msk – Mask determines which LEDs are toggled.

RGB LED (kamami_l496_led_rgb.h)

Library controls RGB LED. Red, green and blue LEDs are controlled with PWM signal generated by 1st, 2nd and 3rd TIM4 channels.
void led_rgb_init(void)
Description:
Initializes all peripherals required for RGB LED: GPIOs and timer for PWM signals generation. Must be called before other led_rgb_ functions.

void led_rgb_set_intensity(uint8_t r_intensity, uint8_t g_intensity, uint8_t b_intensity)
Description:
Sets brightness of red, green and blue LEDs.

Parameters:

  • r_intensity – Red intensity (0-255).
  • g_intensity – Green intensity (0-255).
  • b_intensity – Blue intensity (0-255).

Potentiometer (kamami_l496_pot.h)

Library for reading potentiometer position. It uses 12-bit ADC.
void pot_init(void) 
Description:
Initializes all peripherals required for reading potentiometer position: GPIO and ADC. Must be called before other pot_ functions.

uint16_t pot_read(void)
Description:
Reads potentiometer position. Function is blocking, it initializes ADC conversion, waits for it to complete, returns 12-bit unsigned value.

Return value:

12-bit unsigned value read from ADC.

STLM75M2F Temperature Sensor (kamami_l496_temp.h)

Library for reading temperature from STLM75M2F sensor using I2C.
void temp_lm75_init(void)
Description:
Initializes all peripherals required for reading data from STLM75M2F: GPIO and I2C. Must be called before other temp_lm75_ functions. I2C address jumper must be in 0x48 position.

int8_t temp_lm75_read(void)
Description:
Reads temperature in Celsius degrees.

Return value:

Temperature in Celsius degrees.

LSM303C 6DoF MEMS Sensor (accelerometer/magnetometer) (kamami_l496_mems.h)

Library for reading data from LSM303C sensor using I2C.
uint8_t mems_init(uint8_t acc_datarate, uint8_t acc_fullscale)
Description:
Initializes all peripherals required for reading LSM303C data (GPIO and I2C) and initalizes the sensor. Must be called before other mems_ functions.

Parameters:

  • acc_datarate – Accelerometer data rate. Possible values are:
    • MEMS_ACC_DATARATE_10HZ – 10Hz
    • MEMS_ACC_DATARATE_50HZ – 50Hz
    • MEMS_ACC_DATARATE_100HZ – 100Hz
    • MEMS_ACC_DATARATE_200HZ – 200Hz
    • MEMS_ACC_DATARATE_400HZ – 400Hz
    • MEMS_ACC_DATARATE_800HZ – 800Hz
  • acc_fullscale – Sets range of accelerometer measurement. Possible values are:
    • MEMS_ACC_FULLSCALE_2G – -2G to 2G.
    • MEMS_ACC_FULLSCALE_4G – -2G to 4G.
    • MEMS_ACC_FULLSCALE_8G – -2G to 8G.

Return value:

Function returns 0 on success.

void mems_acc_read_xyz(struct mems_xyz_res* res)
Description:
Reads acceleration values for all axises into mems_xyz_res structure.

Parameters:

  • res – Pointer to mems_xyz_res struct.

int16_t mems_acc_read_x(void);
Description:
Reads and returns acceleration value for X axis.

Return value:

Function returns acceleration value for X axis.

int16_t mems_acc_read_y(void);
Description:
Reads and returns acceleration value for Y axis.

Return value:

Function returns acceleration value for Y axis.

int16_t mems_acc_read_z(void);
Description:
Reads and returns acceleration value for Z axis.

Return value:

Function returns acceleration value for Z axis.

Virtual serial port (USB VCOM) (kamami_l496_temp.h)

Library for VCOM USB communication.
void vcom_init(void)
Description:
Initializes virtual serial port. Must be called before other vcom_ functions.

void vcom_send(uint8_t* buf, uint32_t len)
Description:
Function sends len bytes from buf through virtual serial port. Function should be called from priority level lower than USB interrupt priority (e.g. from main loop).

Parameters:

  • buf – Pointer to buffer with data to send.
  • len – Number of bytes to send.

QSPI Flash Memory (kamami_l496_qspi.h)

Library for QSPI Winbond W25Q80DV Flash Memory.
void qspi_init(void)
Description:
Initializes GPIOs and enables 4-bit memory access mode. Must be called before other qspi_ functions.

void qspi_write(uint32_t address, uint8_t* buffer, uint32_t length)
Description:
Function writes length bytes from buffer to QSPI Flash at specified address.

Parameters:

  • address – Address in QSPI Flash memory.
  • buffer – Pointer to buffer with data to write.
  • length – Number of bytes to write.

void qspi_read(uint32_t address, uint8_t* buffer, uint32_t length)
Description:
Function reads length bytes from QSPI Flash at specified address to buffer.

Parameters:

  • address – Address in QSPI Flash memory.
  • buffer – Pointer to buffer to write data read from QSPI Flash.
  • length – Number of bytes to read.

void qspi_erase_sector(uint32_t address)
Description:
Function erases 4KiB QSPI Flash sector at specified address.

Parameters:

  • address – Address in QSPI Flash memory.

void qspi_erase_chip(void)
Description:
Function erases whole QSPI Flash.

4-digit 7-segment LED Display (kamami_l496_7seg.h)

Library for 4-digit 7-segment LED display.
void dis7seg_init (void)
Description:
Initializes all peripherals required for LED display: GPIO and timer for multiplexing. Must be called before other dis7seg_ functions.

uint8_t dis7seg_display(uint16_t value)
Description:
Displays value on LED display.

Parameters:

  • value – Numerical value to display, value range is 0-9999.

Return value:

Returns 0 on success. If value is out of range then function returns 1.

uint8_t dis7seg_display_fixed_point(uint16_t value, uint8_t fraction_digits)
Description:
Displays fixed point value on LED display.

Parameters:

  • value – Numerical value to display, value range is 0-9999.
  • fraction_digits – Decimal dot position (0-3).

Return value:

Returns 0 on success. If value or fraction_digits is out of range then function returns 1.

Motor Controller (kamami_l496_motor.h)

Motor controller library.
void motor_init (void) 
Description:
Initializes all peripherals required to use motor controller: GPIO and timer for PWM generation. Must be called before other motor_ functions.

void motor_on(void)
Description:
Turns on the motor.

void motor_off(void)
Description:
Turns off the motor.

void motor_set_dir(uint8_t dir) 
Description:
Sets motor direction.

Parameters:

  • dir – Motor direction, possible values: MOTOR_DIR_CLOCKWISE, MOTOR_DIR_COUNTERCLOCKWISE.

void motor_set_speed(uint8_t speed)
Description:
Sets motor speed.

Parameters:

  • speed – Motor speed, range 0-100.

2×16 LCD Display (HD44780 compatible) (kamami_l496_lcd.h)

HD44780 LCD library.
void lcd_init(void)
Description:
Initializes GPIOs required for LCD control and initializes HD44780 controller. Must be called before other lcd_ functions.

void lcd_backlight_on (void)
Description:
Turns on LCD backlight.

void lcd_backlight_off (void)
Description:
Turns off LCD backlight.

void lcd_clear(void)
Description:
Clears LCD.

void lcd_display(char *data, uint8_t len, uint8_t row, uint8_t col)
Description:
Displays characters on LCD.

Parameters:

  • data – Pointer to buffer with data to display.
  • len – Number of characters in buffer to display.
  • row – Number of LCD row (1 or 2).
  • data – Number of LCD column (1-16).

Microphone and Audio Amplifier (kamami_l496_audio.h)

Library recording and playing audio data.
void audio_init(void)
Description:
Initializes all peripherals required for audio recording and playback: GPIO, DAC, ADC and timer. Must be called before other audio_ functions.

void audio_start_rec(uint8_t* buf, uint32_t len)
Description:
Function starts audio recording. Samples are stored in buf buffer (its length is passed by len parameter). Buffer is cyclic, when it is full data is written again at the beginning of buffer.
To handle buffer data you need to define functions:
that will be called after half of the buffer is full and when whole buffer is full.

Parameters:

  • buf – Pointer to buffer for audio data.
  • len – Buffer size.

void audio_stop_rec()
Description:
Function stops audio recording.

void audio_start_play(uint8_t* buf, uint32_t len)
Description:
Function starts audio playback. Samples are read from buf buffer (its length is passed by len parameter). Buffer is cyclic, when playback reaches the end of buffer it starts again at the beginning of buffer.
To handle buffer data you need to define functions:
that will be called after half of the buffer is read and when whole buffer is read.

Parameters:

  • buf – Pointer to buffer with audio data.
  • len – Buffer size.