minipix_uart_interface
A library and examples for the MiniPIX UART interface
mui.h
Go to the documentation of this file.
1 #ifndef MUI_H
2 #define MUI_H
3 
4 #ifdef __cplusplus
5 extern "C" {
6 #endif
7 
8 // definition of packet structures of the measured data
9 #include <llcp_minipix_messages.h>
10 #include <llcp.h>
11 
12 #include <stdint.h>
13 #include <stdbool.h>
14 
15 // gives user more control over protocol handshakes, namely:
16 // * user needs to call mui_getFrameData() after he receives the mui_processFrameMeasurementFinished_t() callback. Otherwise, this callback is not called and
17 // the handshake happens automatically.
18 // * user needs to call mui_sendAck() after receiving FrameData, FrameDataTerminator, Temperature, and Status callbacks.
19 #ifndef MUI_USER_HANDSHAKES
20 #define MUI_USER_HANDSHAKES 0
21 #endif
22 
23 // user can pass the mui_sendString_t to facilitate sending of data
24 #ifndef MUI_SEND_STRING
25 #define MUI_SEND_STRING 0
26 #endif
27 
28 // user can pass the mui_sendChar_t to facilitate sending of data
29 #ifndef MUI_SEND_CHAR
30 #define MUI_SEND_CHAR 0
31 #endif
32 
33 /* automatically-defined configs //{ */
34 
35 #if ((MUI_SEND_CHAR == 1) && (MUI_SEND_STRING == 1))
36 #warning "MUI is compiled with both MUI_SEND_CHAR = 1 and MUI_SEND_STRING = 1, will expect pointer to mui_sendString_t during runtime"
37 #elif ((MUI_SEND_CHAR == 0) && (MUI_SEND_STRING == 0))
38 #error "Cannot have both MUI_SEND_CHAR and MUI_SEND_STRING set to 0. At least one data handling function needs to be used! Please, read README at https://github.com/klaxalk/minipix_uart_interface/tree/master/software/mui for more details."
39 #elif ((MUI_SEND_CHAR == 1) && (MUI_SEND_STRING == 0))
40 #pragma message("MUI is being compiled with MUI_SEND_CHAR = 1, it will expect pointer to the mui_sendChar_t function during runtime")
41 #elif ((MUI_SEND_CHAR == 0) && (MUI_SEND_STRING == 1))
42 #pragma message("MUI is being compiled with MUI_SEND_STRING = 1, it will expect pointer to the mui_sendString_t function during runtime")
43 #endif
44 
45 #if MUI_USER_HANDSHAKES == 1
46 #warning "MUI_USER_HANDSHAKES is 1, do not forget to call mui_sendAck() according to the README"
47 #endif
48 
49 //}
50 
51 // | ---------- function pointers to user's callbacks --------- |
52 
58 typedef void (*mui_ledSetHW_t)(const bool);
59 
66 typedef void (*mui_sendChar_t)(const uint8_t char_out);
67 
75 typedef void (*mui_sendString_t)(const uint8_t *str_out, const uint16_t len);
76 
83 typedef void (*mui_processFrameData_t)(const LLCP_FrameData_t *image_data);
84 
90 
98 
105 typedef void (*mui_processStatus_t)(const LLCP_Status_t *status_data);
106 
113 typedef void (*mui_processTemperature_t)(const LLCP_Temperature_t *temperature_data);
114 
121 typedef void (*mui_processAck_t)(const LLCP_Ack_t *ack_data);
122 
129 typedef void (*mui_processMinipixError_t)(const LLCP_MinipixError_t *error_data);
130 
136 typedef void (*mui_sleepHW_t)(const uint16_t duration);
137 
143 typedef struct
144 {
145  mui_ledSetHW_t ledSetHW;
146  mui_sendChar_t sendChar;
147  mui_sendString_t sendString;
148  mui_processFrameData_t processFrameData;
149  mui_processFrameDataTerminator_t processFrameDataTerminator;
150  mui_processStatus_t processStatus;
151  mui_processTemperature_t processTemperature;
152  mui_processAck_t processAck;
153  mui_processMinipixError_t processMinipixError;
154  mui_processFrameMeasurementFinished_t processFrameMeasurementFinished;
155  mui_sleepHW_t sleepHW;
157 
158 typedef struct
159 {
160  LLCP_Receiver_t llcp_receiver;
162  bool led_state;
163  MUI_FcnPrototypes_t fcns;
164 } MUI_Handler_t;
165 
166 // --------------------------------------------------------------
167 // | public |
168 // --------------------------------------------------------------
169 
170 // | ---------------------- "constructor" --------------------- |
171 
178 void mui_initialize(MUI_Handler_t *mui_handler);
179 
180 // | -------------- interraction with the MiniPIX ------------- |
181 
188 void mui_pwr(MUI_Handler_t *mui_handler, const bool state);
189 
200 void mui_measureFrame(MUI_Handler_t *mui_handler, const uint16_t acquisition_time, const uint8_t mode);
201 
210 void mui_getFrameData(MUI_Handler_t *mui_handler);
211 
218 void mui_setThreshold(MUI_Handler_t *mui_handler, const uint16_t threshold_coarse, const uint16_t threshold_fine);
219 
226 void mui_setConfigurationPreset(MUI_Handler_t *mui_handler, const uint8_t preset);
227 
235 
244 void mui_getStatus(MUI_Handler_t *mui_handle);
245 
254 void mui_getTemperature(MUI_Handler_t *mui_handle);
255 
256 // | ------------- UART communication with MiniPIX ------------ |
257 
264 void mui_receiveCharCallback(MUI_Handler_t *mui_handler, const uint8_t byte_in);
265 
266 // | --------------- the main update() function --------------- |
267 
275 void mui_update(MUI_Handler_t *mui_handler);
276 
283 void mui_sendAck(MUI_Handler_t *mui_handler, const bool success);
284 
285 // --------------------------------------------------------------
286 // | private |
287 // --------------------------------------------------------------
288 
296 void mui_sendMessage(MUI_Handler_t* mui_handler, const uint8_t* message, const uint16_t len);
297 
298 // | -------------------- LED signalization ------------------- |
299 
306 void mui_ledSet(MUI_Handler_t *mui_handler, const bool new_state);
307 
313 void mui_ledToggle(MUI_Handler_t *mui_handler);
314 
315 #ifdef __cplusplus
316 }
317 #endif
318 
319 #endif // MUI_H
mui_processFrameData_t
void(* mui_processFrameData_t)(const LLCP_FrameData_t *image_data)
Function pointer to user implementation of callback to process incoming Frame data.
Definition: mui.h:83
mui_initialize
void mui_initialize(MUI_Handler_t *mui_handler)
The "constructor" of the MUI handler. Should be called by the user just after allocating it.
Definition: mui.c:9
mui_ledSetHW_t
void(* mui_ledSetHW_t)(const bool)
Function pointer for implementation of seting an LED state.
Definition: mui.h:58
mui_ledSet
void mui_ledSet(MUI_Handler_t *mui_handler, const bool new_state)
set LED state
Definition: mui.c:383
mui_processTemperature_t
void(* mui_processTemperature_t)(const LLCP_Temperature_t *temperature_data)
Function pointer to user implementation of callback to process incoming Temperature message.
Definition: mui.h:113
mui_processAck_t
void(* mui_processAck_t)(const LLCP_Ack_t *ack_data)
Function pointer to user implementation of callback to process incoming Ack message.
Definition: mui.h:121
mui_processFrameDataTerminator_t
void(* mui_processFrameDataTerminator_t)(const LLCP_FrameDataTerminator_t *terminator)
Function pointer to user implementation of callback to process incoming Frame data terminator (the la...
Definition: mui.h:97
mui_receiveCharCallback
void mui_receiveCharCallback(MUI_Handler_t *mui_handler, const uint8_t byte_in)
Called by the user with every incoming byte on the UART to the MiniPIX.
Definition: mui.c:187
MUI_FcnPrototypes_t
Structure containing pointers to user callbacks. User shouls provide implementations to all the liste...
Definition: mui.h:143
mui_processMinipixError_t
void(* mui_processMinipixError_t)(const LLCP_MinipixError_t *error_data)
Function pointer to user implementation of callback to process incoming MiniPIX error message.
Definition: mui.h:129
mui_sendAck
void mui_sendAck(MUI_Handler_t *mui_handler, const bool success)
Sends ack to the MiniPIX. Not to be called by the user.
Definition: mui.c:332
mui_getFrameData
void mui_getFrameData(MUI_Handler_t *mui_handler)
Command to request measured frame data. As a result, the MiniPIX will start obtaning data and will ca...
Definition: mui.c:66
mui_sendString_t
void(* mui_sendString_t)(const uint8_t *str_out, const uint16_t len)
Function pointer for implementation of sending a string (array of bytes) over a serial line to MiniPI...
Definition: mui.h:75
mui_pwr
void mui_pwr(MUI_Handler_t *mui_handler, const bool state)
Command to power on/off the Timepix3 chip.
Definition: mui.c:21
mui_update
void mui_update(MUI_Handler_t *mui_handler)
Called by the user to led MUI do stuff in the background. Should be called regularly,...
Definition: mui.c:318
LLCP_Temperature_t
LLCP_Temperature_t
Definition: llcp_minipix_messages.h:935
LLCP_UpdatePixelMaskReq_t
LLCP_UpdatePixelMaskReq_t
Definition: llcp_minipix_messages.h:468
mui_setThreshold
void mui_setThreshold(MUI_Handler_t *mui_handler, const uint16_t threshold_coarse, const uint16_t threshold_fine)
Command to set energy threshold.
Definition: mui.c:106
mui_measureFrame
void mui_measureFrame(MUI_Handler_t *mui_handler, const uint16_t acquisition_time, const uint8_t mode)
Command to acquire a frame over a period of the acquisition_time. As a result, the MiniPIX will start...
Definition: mui.c:44
mui_updatePixelMask
void mui_updatePixelMask(MUI_Handler_t *mui_handler, LLCP_UpdatePixelMaskReq_t *data)
Command to update a mask of a particular pixel.
Definition: mui.c:86
mui_setConfigurationPreset
void mui_setConfigurationPreset(MUI_Handler_t *mui_handler, const uint8_t preset)
Command to set configuration preset.
Definition: mui.c:127
MUI_Handler_t
Definition: mui.h:158
mui_processStatus_t
void(* mui_processStatus_t)(const LLCP_Status_t *status_data)
Function pointer to user implementation of callback to process incoming Status message.
Definition: mui.h:105
LLCP_FrameData_t
LLCP_FrameData_t
Definition: llcp_minipix_messages.h:181
LLCP_Status_t
LLCP_Status_t
Definition: llcp_minipix_messages.h:829
mui_sendChar_t
void(* mui_sendChar_t)(const uint8_t char_out)
Function pointer for implementaion of sending a char (byte) over a serial line to MiniPIX.
Definition: mui.h:66
LLCP_Ack_t
LLCP_Ack_t
Definition: llcp_minipix_messages.h:682
mui_getTemperature
void mui_getTemperature(MUI_Handler_t *mui_handle)
Command to get the temperature of the MinixPIX HW. As a result, the method processTemperature() will ...
Definition: mui.c:167
mui_getStatus
void mui_getStatus(MUI_Handler_t *mui_handle)
Command to get the status of the MinixPIX HW. As a result, the method processStatus() will get called...
Definition: mui.c:149
LLCP_RX_TX_BUFFER_SIZE
#define LLCP_RX_TX_BUFFER_SIZE
Definition: llcp.h:54
mui_ledToggle
void mui_ledToggle(MUI_Handler_t *mui_handler)
toggle the state of the LED
Definition: mui.c:394
LLCP_MinipixError_t
LLCP_MinipixError_t
Definition: llcp_minipix_messages.h:1043
LLCP_FrameDataTerminator_t
LLCP_FrameDataTerminator_t
Definition: llcp_minipix_messages.h:251
tx_buffer
uint8_t tx_buffer[TX_SERIAL_BUFFER_SIZE]
Definition: main.cpp:16
mui_processFrameMeasurementFinished_t
void(* mui_processFrameMeasurementFinished_t)(void)
Function pointer to user implementation of callback to process message regarding that a measurement w...
Definition: mui.h:89
mui_sleepHW_t
void(* mui_sleepHW_t)(const uint16_t duration)
Function pointer for implementation of a sleep function.
Definition: mui.h:136
LLCP_Receiver_t
LLCP_Receiver_t
Definition: llcp.h:107
mui_sendMessage
void mui_sendMessage(MUI_Handler_t *mui_handler, const uint8_t *message, const uint16_t len)
Abstraction above sending a message. Will use either sendString or sendChar basend on configuration.
Definition: mui.c:357