https://www.st.com/en/ecosystems/x-nucleo-plm01a1.html MBED driver for the ST7580 IC.

Committer:
Arthrik
Date:
Sat Apr 20 20:18:49 2019 +0000
Revision:
1:edbcde816013
Parent:
0:e88514a784bb
Data reception now works.; Updated the example code.; It still needs some work, but it's usable

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Arthrik 0:e88514a784bb 1 #ifndef ST7580_H
Arthrik 0:e88514a784bb 2 #define ST7580_H
Arthrik 0:e88514a784bb 3
Arthrik 0:e88514a784bb 4 #include "mbed.h"
Arthrik 0:e88514a784bb 5 #include "ST7580_codes.h"
Arthrik 0:e88514a784bb 6 #include <stdio.h>
Arthrik 0:e88514a784bb 7 #include <string.h>
Arthrik 0:e88514a784bb 8
Arthrik 0:e88514a784bb 9 #define ST7580_TSR 100
Arthrik 0:e88514a784bb 10
Arthrik 0:e88514a784bb 11 /*! \class ST7580
Arthrik 0:e88514a784bb 12 * \brief ST7580 driver
Arthrik 0:e88514a784bb 13 *
Arthrik 0:e88514a784bb 14 * here is a minimal example:
Arthrik 1:edbcde816013 15 * void callback_function(unsigned char *data, int payload_length)
Arthrik 1:edbcde816013 16 * {
Arthrik 1:edbcde816013 17 * //Do what you want with the data
Arthrik 1:edbcde816013 18 * }
Arthrik 1:edbcde816013 19 * int main() {
Arthrik 1:edbcde816013 20 * ST7580 shield(D8, D2, D13, D7, callback_function);
Arthrik 0:e88514a784bb 21 * shield.init();
Arthrik 0:e88514a784bb 22 * wait(1);
Arthrik 0:e88514a784bb 23 * while(1) {
Arthrik 0:e88514a784bb 24 * shield.send_frame("Hello world!");
Arthrik 0:e88514a784bb 25 * }
Arthrik 1:edbcde816013 26 * }
Arthrik 0:e88514a784bb 27 */
Arthrik 0:e88514a784bb 28 class ST7580
Arthrik 0:e88514a784bb 29 {
Arthrik 0:e88514a784bb 30 public:
Arthrik 0:e88514a784bb 31 /*!
Arthrik 0:e88514a784bb 32 * \brief Constructor
Arthrik 0:e88514a784bb 33 *
Arthrik 0:e88514a784bb 34 * ST7580 Constructor
Arthrik 0:e88514a784bb 35 *
Arthrik 0:e88514a784bb 36 * \param tx : mbed UART transmission pin
Arthrik 0:e88514a784bb 37 * \param rx : mbed UART reception pin
Arthrik 0:e88514a784bb 38 * \param t_req : ST7580 transmit request pin
Arthrik 0:e88514a784bb 39 * \param reset : ST7580 reset pin
Arthrik 0:e88514a784bb 40 * \param usr_callback : callback to the user app with reception buffer, and payload length as arguments
Arthrik 0:e88514a784bb 41 */
Arthrik 0:e88514a784bb 42 ST7580(PinName tx, PinName rx, PinName t_req, PinName reset, void (*usr_callback)(unsigned char *, int));
Arthrik 0:e88514a784bb 43
Arthrik 0:e88514a784bb 44 /*!
Arthrik 0:e88514a784bb 45 * \brief Initialises the pins and UART needed for the driver
Arthrik 0:e88514a784bb 46 *
Arthrik 0:e88514a784bb 47 * Creates the UART handle and needed pins
Arthrik 0:e88514a784bb 48 */
Arthrik 0:e88514a784bb 49 void init();
Arthrik 0:e88514a784bb 50 void send_frame(unsigned char *msg, int msg_length);
Arthrik 0:e88514a784bb 51
Arthrik 0:e88514a784bb 52 private:
Arthrik 0:e88514a784bb 53 void wait_status();
Arthrik 0:e88514a784bb 54 void wait_reset();
Arthrik 0:e88514a784bb 55 void reset_reception_buffer();
Arthrik 0:e88514a784bb 56 void rx_complete();
Arthrik 0:e88514a784bb 57 void rx_callback();
Arthrik 0:e88514a784bb 58
Arthrik 0:e88514a784bb 59 void (*_usr_callback)(unsigned char *, int);
Arthrik 0:e88514a784bb 60 volatile unsigned char _rx_char;
Arthrik 1:edbcde816013 61 volatile unsigned char _rcv_data[255];
Arthrik 0:e88514a784bb 62 volatile int _rcv_data_idx;
Arthrik 0:e88514a784bb 63 volatile int _rcv_data_offset;
Arthrik 1:edbcde816013 64 volatile int _rcv_payload_len;
Arthrik 0:e88514a784bb 65
Arthrik 0:e88514a784bb 66 DigitalOut *_plm_t_req;
Arthrik 0:e88514a784bb 67 DigitalOut *_plm_reset;
Arthrik 0:e88514a784bb 68 RawSerial *_plm_uart;
Arthrik 0:e88514a784bb 69 };
Arthrik 0:e88514a784bb 70
Arthrik 1:edbcde816013 71 #endif