minipro.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #ifndef __MINIPRO_H
  2. #define __MINIPRO_H
  3. /* This header is only containing the low-level wrappers against typical requests.
  4. * Please refer main.c if you're looking for a higher-level logic. */
  5. #include <libusb.h>
  6. #define MP_TL866A 1
  7. #define MP_TL866CS 2
  8. #define MP_FIRMWARE_VERSION 0x023d
  9. #define MP_REQUEST_STATUS1_MSG1 0x03
  10. #define MP_REQUEST_STATUS1_MSG2 0xfe
  11. #define MP_GET_SYSTEM_INFO 0x00
  12. #define MP_GET_CHIP_ID 0x05
  13. #define MP_READ_CODE 0x21
  14. #define MP_READ_DATA 0x30
  15. #define MP_WRITE_CODE 0x20
  16. #define MP_WRITE_DATA 0x31
  17. #define MP_PREPARE_WRITING 0x22
  18. #define MP_READ_CFG 0x12
  19. #define MP_WRITE_CFG 0x13
  20. #define MP_PROTECT_OFF 0x44
  21. #define MP_PROTECT_ON 0x45
  22. #define MP_ICSP_ENABLE 0x80
  23. #define MP_ICSP_VCC 0x01
  24. #define MAX_READ_BUFFER_SIZE 0x400
  25. #define MAX_WRITE_BUFFER_SIZE 0x210
  26. #include "database.h"
  27. typedef struct minipro_system_info {
  28. unsigned char protocol;
  29. unsigned char model;
  30. char *model_str;
  31. unsigned int firmware;
  32. char firmware_str[16];
  33. } minipro_system_info_t;
  34. typedef struct minipro_handle {
  35. libusb_device_handle *usb_handle;
  36. libusb_context *ctx;
  37. device_t *device;
  38. int icsp;
  39. } minipro_handle_t;
  40. minipro_handle_t *minipro_open(device_t *device);
  41. void minipro_close(minipro_handle_t *handle);
  42. void minipro_begin_transaction(minipro_handle_t *handle);
  43. void minipro_end_transaction(minipro_handle_t *handle);
  44. void minipro_protect_off(minipro_handle_t *handle);
  45. void minipro_protect_on(minipro_handle_t *handle);
  46. int minipro_get_status(minipro_handle_t *handle);
  47. void minipro_read_block(minipro_handle_t *handle, unsigned int type, unsigned int addr, unsigned char *buf, unsigned int len);
  48. void minipro_write_block(minipro_handle_t *handle, unsigned int type, unsigned int addr, unsigned char *buf, unsigned int len);
  49. int minipro_get_chip_id(minipro_handle_t *handle);
  50. void minipro_read_fuses(minipro_handle_t *handle, unsigned int type, unsigned int length, unsigned char *buf);
  51. void minipro_write_fuses(minipro_handle_t *handle, unsigned int type, unsigned int length, unsigned char *buf);
  52. void minipro_prepare_writing(minipro_handle_t *handle);
  53. void minipro_get_system_info(minipro_handle_t *handle, minipro_system_info_t *out);
  54. #endif