-
Notifications
You must be signed in to change notification settings - Fork 185
/
pgm.h
69 lines (57 loc) · 1.56 KB
/
pgm.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#ifndef __PGM_H
#define __PGM_H
#if defined(WIN32) || defined(__CYGWIN__)
#include <libusb-1.0/libusb.h>
#else
#include <libusb.h>
#endif
#include "stm8.h"
#include "libespstlink.h"
typedef enum {
UNKNOWN,
RAM,
EEPROM,
FLASH,
OPT,
} memtype_t;
typedef enum {
NONE = 0,
READ,
WRITE,
VERIFY,
RESET,
UNLOCK
} action_t;
typedef enum {
STLinkV1,
STLinkV2,
STLinkV21,
STLinkV3,
ESP_STLink
} programmer_type_t;
typedef struct programmer_s {
/* Info */
const char *name;
programmer_type_t type;
unsigned int usb_vid;
unsigned int usb_pid;
/* Methods */
bool (*open) (struct programmer_s *pgm);
void (*close) (struct programmer_s *pgm);
void (*reset) (struct programmer_s *pgm);
int (*read_range) (struct programmer_s *pgm, const stm8_device_t *device, unsigned char *buffer, unsigned int start, unsigned int length);
int (*write_range) (struct programmer_s *pgm, const stm8_device_t *device, unsigned char *buffer, unsigned int start, unsigned int length, const memtype_t memtype);
/* Private */
libusb_device_handle *dev_handle;
libusb_context *ctx;
unsigned int msg_count; // debugging only
unsigned int out_msg_size; // stlink/stlinkv2
/* Data for espstlink module. */
espstlink_t * espstlink;
const char *port;
} programmer_t;
typedef bool (*pgm_open_cb)(programmer_t *);
typedef void (*pgm_close_cb)(programmer_t *);
typedef int (*pgm_read_range_cb)(programmer_t *, unsigned char *, unsigned int, unsigned int);
typedef int (*pgm_write_range_cb)(programmer_t *, unsigned char *, unsigned int, unsigned int);
#endif