source: avrstuff/V-USB_Dev/firmwares/herePic/driver/icsp.h@ 8659a17

main
Last change on this file since 8659a17 was 8659a17, checked in by Adrien Destugues <pulkomandy@…>, 12 years ago

Progress on the host driver. Still untested.

git-svn-id: svn://pulkomandy.tk/avrstuff@66 c6672c3c-f6b6-47f9-9001-1fd6b12fecbe

  • Property mode set to 100644
File size: 1.7 KB
Line 
1/* HEREPIC - AVR-based ICSP programmer for microchip PIC16F6xx and 16F8xx devices
2 * Copyright 2012, Adrien Destugues <pulkomandy@pulkomandy.tk>
3 *
4 * This file is distributed under the terms of the MIT licence.
5 */
6
7#include <string.h>
8
9class ICSP
10{
11 public:
12 ICSP(BUSBDevice& device)
13 : fDevice(device)
14 {
15 }
16
17 uint16_t Execute(ICSPCommands command, uint16_t param = 0)
18 {
19 // TODO send the command to the device
20 uint16 length;
21 uint8 reqType = USB_REQTYPE_VENDOR;
22 if(command == ReadCodeWord || command == ReadDataWord)
23 {
24 length = 2;
25 reqType |= USB_REQTYPE_DEVICE_OUT;
26 } else {
27 length = 0;
28 reqType |= USB_REQTYPE_DEVICE_IN;
29 }
30
31 ssize_t result = fDevice.ControlTransfer(reqType, command, param, 0,
32 length, &param);
33 if (result == length) {
34 // We transferred as much bytes as we wanted.
35 // Everyone is happy !
36 return param;
37 } else {
38 // Not enough bytes transferred, or the result is an error code
39 std::cerr << "USB communication error " << result
40 << "(" << strerror(result) << ")" << std::endl;;
41 return result;
42 }
43 }
44
45 void Write(const char* filename)
46 {
47 std::cerr << "Sorry, this doesn't work yet !" << std::endl;
48 exit(-4);
49 }
50
51 void Read(const char* filename)
52 {
53 std::cerr << "Sorry, this doesn't work yet !" << std::endl;
54 exit(-4);
55 }
56
57 void Erase()
58 {
59 // Let's test some stuff...
60 std::cout << std::hex;
61
62 Execute(LoadConfigWord); // sets PC to 0x2000 to read CFG words
63 for(int i = 8; --i >= 0;)
64 {
65 uint16_t word = Execute(ReadCodeWord);
66 Execute(NextAddress);
67
68 std::cout << word << " ";
69 }
70 std::cout << std::endl;
71 }
72
73 private:
74 BUSBDevice& fDevice;
75};
Note: See TracBrowser for help on using the repository browser.