Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
dwm_uart.h@0:bb732ce5e423, 2019-03-25 (annotated)
- Committer:
- nguyentony
- Date:
- Mon Mar 25 16:32:43 2019 +0000
- Revision:
- 0:bb732ce5e423
- Child:
- 1:c13dab1b7b93
simple program to work with DWM1001
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| nguyentony | 0:bb732ce5e423 | 1 | #ifndef _DWM_UART_H_ |
| nguyentony | 0:bb732ce5e423 | 2 | #define _DWM_UART_H_ |
| nguyentony | 0:bb732ce5e423 | 3 | #include "mbed.h" |
| nguyentony | 0:bb732ce5e423 | 4 | |
| nguyentony | 0:bb732ce5e423 | 5 | #define HAL_UART_MAX_LENGTH 255 |
| nguyentony | 0:bb732ce5e423 | 6 | #define DWM_WRITE_TIMEOUT 600 //us |
| nguyentony | 0:bb732ce5e423 | 7 | #define DWM_READ_TIMEOUT 3 //ms |
| nguyentony | 0:bb732ce5e423 | 8 | |
| nguyentony | 0:bb732ce5e423 | 9 | /** |
| nguyentony | 0:bb732ce5e423 | 10 | * @brief DWM Error codes, returned from DWM1001 module |
| nguyentony | 0:bb732ce5e423 | 11 | */ |
| nguyentony | 0:bb732ce5e423 | 12 | #define DWM_OK (0) |
| nguyentony | 0:bb732ce5e423 | 13 | #define DWM_ERR_INTERNAL (-1) |
| nguyentony | 0:bb732ce5e423 | 14 | #define DWM_ERR_BUSY (-2) |
| nguyentony | 0:bb732ce5e423 | 15 | #define DWM_ERR_INVAL_ADDR (-3) |
| nguyentony | 0:bb732ce5e423 | 16 | #define DWM_ERR_INVAL_PARAM (-4) |
| nguyentony | 0:bb732ce5e423 | 17 | #define DWM_ERR_OVERRUN (-5) |
| nguyentony | 0:bb732ce5e423 | 18 | #define DWM_ERR_I2C_ANACK (-10) |
| nguyentony | 0:bb732ce5e423 | 19 | #define DWM_ERR_I2C_DNACK (-11) |
| nguyentony | 0:bb732ce5e423 | 20 | |
| nguyentony | 0:bb732ce5e423 | 21 | /** |
| nguyentony | 0:bb732ce5e423 | 22 | * @brief Return value Error codes, returned from DWM API functions |
| nguyentony | 0:bb732ce5e423 | 23 | */ |
| nguyentony | 0:bb732ce5e423 | 24 | #define RV_OK 0 /* ret value OK */ |
| nguyentony | 0:bb732ce5e423 | 25 | #define RV_ERR -1 |
| nguyentony | 0:bb732ce5e423 | 26 | #define RV_TIME -2 /* ret value ERROR*/ |
| nguyentony | 0:bb732ce5e423 | 27 | |
| nguyentony | 0:bb732ce5e423 | 28 | typedef struct { |
| nguyentony | 0:bb732ce5e423 | 29 | int32_t x; |
| nguyentony | 0:bb732ce5e423 | 30 | int32_t y; |
| nguyentony | 0:bb732ce5e423 | 31 | int32_t z; |
| nguyentony | 0:bb732ce5e423 | 32 | uint8_t qf; |
| nguyentony | 0:bb732ce5e423 | 33 | } dwm_pos; |
| nguyentony | 0:bb732ce5e423 | 34 | |
| nguyentony | 0:bb732ce5e423 | 35 | |
| nguyentony | 0:bb732ce5e423 | 36 | class dwm |
| nguyentony | 0:bb732ce5e423 | 37 | { |
| nguyentony | 0:bb732ce5e423 | 38 | public: |
| nguyentony | 0:bb732ce5e423 | 39 | dwm(PinName tx_pin, PinName rx_pin, int baudrate); |
| nguyentony | 0:bb732ce5e423 | 40 | dwm_pos node_pos; |
| nguyentony | 0:bb732ce5e423 | 41 | /*==================================================== |
| nguyentony | 0:bb732ce5e423 | 42 | * API |
| nguyentony | 0:bb732ce5e423 | 43 | * =================================================== |
| nguyentony | 0:bb732ce5e423 | 44 | */ |
| nguyentony | 0:bb732ce5e423 | 45 | |
| nguyentony | 0:bb732ce5e423 | 46 | /* |
| nguyentony | 0:bb732ce5e423 | 47 | * @brief: la commande dans l'exemple du doc, pour tester |
| nguyentony | 0:bb732ce5e423 | 48 | * @param: non |
| nguyentony | 0:bb732ce5e423 | 49 | * @output: 0 - reussi |
| nguyentony | 0:bb732ce5e423 | 50 | * 1 - echec |
| nguyentony | 0:bb732ce5e423 | 51 | */ |
| nguyentony | 0:bb732ce5e423 | 52 | int dwm_gpio_cfg_output(); |
| nguyentony | 0:bb732ce5e423 | 53 | /* |
| nguyentony | 0:bb732ce5e423 | 54 | * @brief: recuperer la position x, y, z, qui seront stockes dans pos |
| nguyentony | 0:bb732ce5e423 | 55 | * @param: la struc dwm_pos |
| nguyentony | 0:bb732ce5e423 | 56 | * @output: 0 - reussi |
| nguyentony | 0:bb732ce5e423 | 57 | * 1 - echec |
| nguyentony | 0:bb732ce5e423 | 58 | */ |
| nguyentony | 0:bb732ce5e423 | 59 | int dwm_pos_get(); |
| nguyentony | 0:bb732ce5e423 | 60 | //====================================== |
| nguyentony | 0:bb732ce5e423 | 61 | // PRIVATE |
| nguyentony | 0:bb732ce5e423 | 62 | //===================================== |
| nguyentony | 0:bb732ce5e423 | 63 | private: |
| nguyentony | 0:bb732ce5e423 | 64 | Serial dwm_uart; |
| nguyentony | 0:bb732ce5e423 | 65 | |
| nguyentony | 0:bb732ce5e423 | 66 | //vider le buffer rx de nucleo |
| nguyentony | 0:bb732ce5e423 | 67 | void flushSerialBuffer(); |
| nguyentony | 0:bb732ce5e423 | 68 | /* |
| nguyentony | 0:bb732ce5e423 | 69 | * @brief: envoyer la commande |
| nguyentony | 0:bb732ce5e423 | 70 | * @param: *tx_buffer - le tableau pour la commande |
| nguyentony | 0:bb732ce5e423 | 71 | len - la longeur du commande |
| nguyentony | 0:bb732ce5e423 | 72 | * @output: 0 - reussi |
| nguyentony | 0:bb732ce5e423 | 73 | * -1 - echec |
| nguyentony | 0:bb732ce5e423 | 74 | */ |
| nguyentony | 0:bb732ce5e423 | 75 | int uart_write(uint8_t* tx_buffer, uint8_t len); |
| nguyentony | 0:bb732ce5e423 | 76 | /* |
| nguyentony | 0:bb732ce5e423 | 77 | * @brief: recevoir la commande |
| nguyentony | 0:bb732ce5e423 | 78 | * @param: *rx_buffer - la reponse est stocke dans rx_buffer |
| nguyentony | 0:bb732ce5e423 | 79 | * @output: la longeur de la reponse |
| nguyentony | 0:bb732ce5e423 | 80 | * -1 - echec |
| nguyentony | 0:bb732ce5e423 | 81 | */ |
| nguyentony | 0:bb732ce5e423 | 82 | int uart_read(uint8_t* rx_buffer, int len_prevu); |
| nguyentony | 0:bb732ce5e423 | 83 | }; |
| nguyentony | 0:bb732ce5e423 | 84 | #endif //_DWM_UART_H_ |