FPGA Module¶
Note
Features¶
Seven Segments¶
Four seven segment displays can be found on the backside of the Leguan Board. They are controlled by the FPGA in one of three modes:
// Display the value 1234 on the seven segments
FPGA_7SegDisplayDecimal(1234);
// Display the value 0xABCD on the seven segments
FPGA_7SegDisplayHexadecimal(0xABCD);
// Display Pi with three decimal places precision (3.141) on the seven segments
FPGA_7SegDisplayFloat(3.141592654, 3);
-
result_t FPGA_7SegDisplayDecimal(uint16_t value)¶
Displays a decimal value between 0 and 9999 on the 7 Segments.
- Parameters
value – Integer to display
-
result_t FPGA_7SegDisplayHexadecimal(uint16_t value)¶
Displays a hexadecimal value between 0x00 and 0xFFFF on the 7 Segments.
- Parameters
value – Integer to display
-
result_t FPGA_7SegDisplayFloat(float32_t value, uint8_t precision)¶
Displays a floating point value on the 7 Segments.
- Parameters
value – Floating point to display
precision – Number of decimal places to be displayed (maximum 3)
DIP Switches¶
Two 8-Bit DIP Switches can be found just below the seven segments.
The value configured on each switch can be read individually with the following functions, where each bit of the returned value corresponds to the state of one switch.
uint8_t left_switches = FPGA_DIPGetLeft();
uint8_t right_switches = FPGA_DIPGetRight();
if (left_switches & 0b1000000)
LOG_Info("Switch 8 of left DIP switches is ON");
-
uint8_t FPGA_DIPGetLeft(void)¶
Gets the value of the left DIP switches.
- Returns
Binary representation of enabled switches
-
uint8_t FPGA_DIPGetRight(void)¶
Gets the value of the right DIP switches.
- Returns
Binary representation of enabled switches
The state of the DIP switches can also be monitored by an interrupt controller that lives inside the FPGA.
The interrupt controller can issue an external interrupt to the MCU when a switch is turned on or off.
// Trigger an interrupt when switch 1 of the right DIP switch array is turned on
FPGA_DIPUnmaskOnIRQ(0);
// Trigger an interrupt when switch 5 of the right DIP switch array is turned off
FPGA_DIPUnmaskOffIRQ(4);
// Trigger an interrupt when switch 2 of the left DIP switch array is turned on or off
FPGA_DIPUnmaskOnIRQ(9);
FPGA_DIPUnmaskOffIRQ(9);
// Disable all interrupts again
FPGA_DIPMaskOnIRQ(0);
FPGA_DIPMaskOffIRQ(4);
FPGA_DIPMaskOnIRQ(9);
FPGA_DIPMaskOffIRQ(9);
-
result_t FPGA_DIPUnmaskOnIRQ(uint8_t switch_id)¶
Unmasks (enables) the “switch moved to ON position” interrupt for one switch.
- Parameters
switch_id – Number of the switch between 1 and 8
-
result_t FPGA_DIPUnmaskOffIRQ(uint8_t switch_id)¶
Unmasks (enables) the “switch moved to OFF position” interrupt for one switch.
- Parameters
switch_id – Number of the switch between 1 and 8
-
result_t FPGA_DIPMaskOnIRQ(uint8_t switch_id)¶
Masks (disables) the “switch moved to ON position” interrupt for one switch.
- Parameters
switch_id – Number of the switch between 1 and 8
-
result_t FPGA_DIPMaskOffIRQ(uint8_t switch_id)¶
Masks (disables) the “switch moved to OFF position” interrupt for one switch.
- Parameters
switch_id – Number of the switch between 1 and 8
Buttons and Joystick¶
The four buttons and the pseudo-joystick are also connected directly to the FPGA. Similar to the DIP switches, their value can be read out.
bool button1_state = FPGA_GetButton(Button1);
bool north = FPGA_GetButton(JoystickNorth);
bool south = FPGA_GetButton(JoystickSouth);
-
bool FPGA_GetButton(FPGA_Button_t button)¶
Queries the state of a button or the joystick.
- Parameters
button – Button to query
- Returns
State of button
They are also hooked up to the interrupt controller to monitor buttons being pressed and released.
// Trigger an interrupt when Button 2 is pressed
FPGA_ButtonUnmaskPressIRQ(Button2);
// Trigger an interrupt when the Joystick center button is released
FPGA_ButtonUnmaskReleaseIRQ(JoystickCenter);
// Disable interrupts again
FPGA_ButtonMaskPressIRQ(Button2);
FPGA_ButtonMaskReleaseIRQ(JoystickCenter);
-
result_t FPGA_ButtonUnmaskPressIRQ(FPGA_Button_t button)¶
Unmasks (enables) the “button pressed” interrupt for one button.
- Parameters
button – Button to enable interrupt for
-
result_t FPGA_ButtonUnmaskReleaseIRQ(FPGA_Button_t button)¶
Unmasks (enables) the “button released” interrupt for one button.
- Parameters
button – Button to enable interrupt for
-
result_t FPGA_ButtonMaskPressIRQ(FPGA_Button_t button)¶
Masks (disables) the “button pressed” interrupt for one switch.
- Parameters
button – Button to disable interrupt for
-
result_t FPGA_ButtonMaskReleaseIRQ(FPGA_Button_t button)¶
Masks (disables) the “button released” interrupt for one switch.
- Parameters
button – Button to disable interrupt for
RGB LED Matrix¶
Each LED of the RGB LED Matrix can be addressed individually through the FPGA. 8 Different colors are supported which corresponds to a 3 bit per pixel color
// Set the color of the top left LED to red, the one below to green and the one below that to blue
FPGA_MatrixSetPixel(0, 0, ColorRed);
FPGA_MatrixSetPixel(0, 1, ColorGreen);
FPGA_MatrixSetPixel(0, 2, ColorBlue);
-
result_t FPGA_MatrixSetPixel(uint8_t x, uint8_t y, color_t color)¶
Sets the color of one pixel on the RGB LED Matrix.
- Parameters
x – X coordinate of the pixel
y – Y coordinate of the pixel
red – Red LED State
green – Green LED State
blue – Blue LED State