├── .gitignore ├── .gitmodules ├── CMakeLists.txt ├── LICENSE ├── README.md ├── firmware ├── FIRMWARE.BIN └── FIRMWARE.PD2 ├── idf ├── CMakeLists.txt ├── LICENSE ├── main │ ├── CMakeLists.txt │ ├── D64DataSource.cpp │ ├── D64DataSource.h │ ├── DataSource.h │ ├── EspConn.cpp │ ├── EspConn.h │ ├── EspHttp.cpp │ ├── EspHttp.h │ ├── FAT32.cpp │ ├── FAT32.h │ ├── HTTPClient.cpp │ ├── HTTPClient.h │ ├── HTTPDataSource.cpp │ ├── HTTPDataSource.h │ ├── IEEE488.cpp │ ├── IEEE488.h │ ├── Logger.h │ ├── NetworkDataSource.cpp │ ├── NetworkDataSource.h │ ├── SD_routines.cpp │ ├── SD_routines.h │ ├── SPI_routines.cpp │ ├── SPI_routines.h │ ├── Settings.cpp │ ├── Settings.h │ ├── base64.cpp │ ├── base64.hpp │ ├── cbmlayout.h │ ├── console.cpp │ ├── console.h │ ├── hardware.h │ ├── hardware_esp32.cpp │ ├── hardware_esp32.h │ ├── helpers.cpp │ ├── helpers.h │ ├── http.cpp │ ├── http.h │ ├── main.cpp.bak │ └── petdisk.cpp ├── partitions.csv ├── scripts │ ├── GitHash.cmake │ └── githash.py ├── sdkconfig.defaults ├── sdkconfig.defaults.esp32 ├── sdkconfig.defaults.esp32s2 └── www │ └── petdisk.php ├── legacy ├── LICENSE ├── Makefile ├── PETDISK.CFG ├── githash.py ├── partitions.csv ├── platformio.ini ├── reset.py ├── sdkconfig.sd_loader └── src │ ├── CMakeLists.txt │ ├── ConsoleLogger.cpp │ ├── ConsoleLogger.h │ ├── D64DataSource.cpp │ ├── D64DataSource.h │ ├── DataSource.h │ ├── EspConn.h │ ├── EspHttp.cpp │ ├── EspHttp.h │ ├── EspLogger.h │ ├── FAT32.cpp │ ├── FAT32.h │ ├── IEEE488.cpp │ ├── IEEE488.h │ ├── Logger.h │ ├── NetworkDataSource.cpp │ ├── NetworkDataSource.h │ ├── SD_routines.cpp │ ├── SD_routines.h │ ├── SPI_routines.cpp │ ├── SPI_routines.h │ ├── Serial.cpp │ ├── Serial.h │ ├── SerialLogger.h │ ├── Settings.cpp │ ├── Settings.h │ ├── avr │ ├── EspConn.cpp │ ├── avr_main.cpp │ ├── bootloader │ │ ├── DataSource.h │ │ ├── FAT32_tiny.cpp │ │ ├── FAT32_tiny.h │ │ ├── Logger.h │ │ ├── SD_routines.cpp │ │ ├── SD_routines.h │ │ ├── SPI_routines.cpp │ │ ├── SPI_routines.h │ │ ├── Serial.h │ │ ├── SerialLogger.h │ │ └── bootloader.cpp │ ├── d64_test.cpp │ ├── fsDataSource.cpp │ ├── fsDataSource.h │ ├── hardware_avr.cpp │ └── hardware_avr.h │ ├── base64.cpp │ ├── base64.h │ ├── cbmlayout.h │ ├── esp32 │ ├── EspConn.cpp │ ├── hardware_esp32.cpp │ └── hardware_esp32.h │ ├── hardware.h │ ├── helpers.cpp │ ├── helpers.h │ ├── petdisk.cpp │ ├── sd_loader │ └── sd_loader.cpp │ └── tools │ └── filesize.cpp ├── schematics ├── PETdisk_MAX_Schematic.pdf ├── dip_version │ ├── gerbers │ │ ├── petdisk_max_dip_board_outline.gm1 │ │ ├── petdisk_max_dip_bottom_copper.gbl │ │ ├── petdisk_max_dip_bottom_paste.gbp │ │ ├── petdisk_max_dip_bottom_silk.gbo │ │ ├── petdisk_max_dip_bottom_soldermask.gbs │ │ ├── petdisk_max_dip_drills.txt │ │ ├── petdisk_max_dip_drills_NPTH.txt │ │ ├── petdisk_max_dip_top_copper.gtl │ │ ├── petdisk_max_dip_top_paste.gtp │ │ ├── petdisk_max_dip_top_silk.gto │ │ └── petdisk_max_dip_top_soldermask.gts │ ├── petdisk_max_dip.brd │ ├── petdisk_max_dip.sch │ └── petdisk_max_dip_partlist.txt ├── petdisk_esp32.pdf └── tape_power_adapter │ ├── gerbers │ ├── tape_power_adapter_board_outline.gm1 │ ├── tape_power_adapter_bottom_copper.gbl │ ├── tape_power_adapter_bottom_paste.gbp │ ├── tape_power_adapter_bottom_silk.gbo │ ├── tape_power_adapter_bottom_soldermask.gbs │ ├── tape_power_adapter_drills.txt │ ├── tape_power_adapter_drills_NPTH.txt │ ├── tape_power_adapter_top_copper.gtl │ ├── tape_power_adapter_top_paste.gtp │ ├── tape_power_adapter_top_silk.gto │ └── tape_power_adapter_top_soldermask.gts │ ├── tape_power_adapter.brd │ └── tape_power_adapter.sch ├── test └── Makefile └── www └── petdisk.php /.gitignore: -------------------------------------------------------------------------------- 1 | .pio 2 | .vscode/.browse.c_cpp.db* 3 | .vscode/c_cpp_properties.json 4 | .vscode/launch.json 5 | .vscode/ipch 6 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "idf/components/esp-fast-gpio"] 2 | path = idf/components/esp-fast-gpio 3 | url = git@github.com:bitfixer/esp-fast-gpio.git 4 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.16.0) 2 | include($ENV{IDF_PATH}/tools/cmake/project.cmake) 3 | project(petdisk-max) 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # petdisk-max 2 | Firmware and schematics for the PETdisk MAX storage device for Commodore PET 3 | 4 | The PETdisk MAX is a storage device for the Commodore PET series of computers. It can use both a microSD card and can also access up to 4 network drives. 5 | The network drives are essentially directories of files hosted on standard web servers. They can be configured as read/write or readonly. Currently PHP support is required on a web server to be used as a network drive - simply copy the [petdisk.php](https://raw.githubusercontent.com/bitfixer/petdisk-max/main/www/petdisk.php) file into a directory on a web server along with some PET files, and you're ready to go. 6 | 7 | ## Installation 8 | 9 | The PETdisk MAX plugs into the IEEE-488 port on the back of your PET. Looking at the back of the PET, this is the edge connector on the right side. 10 | Since the IEEE-488 port does not supply power, a separate power connection is required. 11 | Depending on when you received your PETdisk MAX, this will either be a small board which fits into one of the PET's ROM sockets and provides a 5v power pin, or a clip which connects to the PETdisk with a wire lead. 12 | 13 | First, open up the PET. 14 | 15 | ### For the ROM socket: 16 | If you have any ROM sockets free, choose the one closest to the PETdisk and install the board into the socket on the mainboard, making sure to align the notches on both sockets. 17 | If no ROM sockets are free, first remove a ROM chip from the mainboard, install the socket, and then reinstall the ROM chip into the new socket. Make sure to line the notches up. 18 | Then connect the wire lead included with the PETdisk to the 5v pin, and feed the other end out the back of the PET through the opening around the IEEE-488 connector. 19 | 20 | ### For the clip: 21 | You'll need to clip onto a 5v source on the mainboard. An easy place to find this is on one of the 6520 chips, there are 2 of them in the PET. They are located close on the board to the IEEE-488 port. Locate one of the 6520 chips, they will be close to the back of the board and labeled '6520' somewhere on the chip. Not to be confused with the '6502' also on the board. 22 | 23 | Locations of 6520s in some PET motherboards:\ 24 | 2001: UB8 and UG8\ 25 | 2001N: UC6 and UC7\ 26 | 8032: UB16 and UB12 27 | 28 | Pick the more conveniently located 6520, and find pin 20. If you are looking at the chip with the notch up, go to the left side of the chip and go down to the lower left corner. Clip on to this pin and then feed the wire lead out the back through the opening around the IEEE-488 connector. 29 | If you prefer, you can clip on to any capacitor lead connected to 5v in the computer, there are several. 30 | 31 | Moving to the back of the PET, connect the wire lead to the PETdisk MAX. There is a connector on the back of the PETdisk, and the position on the connector furthest to the right side of the device is labeled '5v'. Connect here, double check that you are connected in the furthest right position, closest to the edge of the board. 32 | 33 | After this, just plug the PETdisk MAX into the IEEE-488 connector and you're ready to go. 34 | 35 | ## Configuration 36 | 37 | The default configuration of the PETdisk MAX uses the built-in sd card as device 8. 38 | You can change this device number as well as setting up a maximum of 4 network drives by editing this file template: 39 | [PETDISK.CFG](https://raw.githubusercontent.com/bitfixer/petdisk-max/main/PETDISK.CFG)\ 40 | Each line of the file consists of the drive number, comma, text specifying the drive. 41 | SD0 refers to the built-in SD card. Change the drive number here if you like. 42 | For network drives, the specifier is the full URL of the drive script. Up to 4 can be used at once. 43 | Remove any lines with URLs if you don't want to use any network drives at that time. 44 | 45 | The last 2 lines of the file contain the ssid and password for your wifi network, replace the placeholders with the information for your network. Note that only 2.4 Ghz wifi networks are supported. 46 | 47 | Copy the edited file onto the root directory of your SD card. On the next power up, the new configuration will be read. 48 | 49 | ## Operation 50 | 51 | Basic drive operations are the same as other Commodore storage devices. 52 | Load a directory with 53 | LOAD"$",devicenumber 54 | and 55 | LIST 56 | 57 | For BASIC 4, the CATALOG and DIRECTORY commands will also work. 58 | 59 | Load a program (.PRG) with 60 | LOAD"PROGRAM",devicenumber 61 | 62 | or save with 63 | SAVE"PROGRAM",devicenumber 64 | 65 | The DLOAD command also works. 66 | 67 | ## Subdirectories 68 | 69 | To change directories on a FAT32 volume, use 70 | LOAD"$:dirname",devicenumber 71 | 72 | This also loads the directory listing of the new directory. 73 | 74 | Return to the previous directory with 75 | LOAD"$:..",devicenumber 76 | 77 | ## D64 78 | 79 | The PETdisk MAX currently supports D64 files for both reading and writing. 80 | To mount a D64 file stored on either an SD card or network drive, 81 | use the following command: 82 | LOAD"$:filename.d64",devicenumber 83 | 84 | This will mount the D64 file as the disk for the specified device number. It will also load the directory of the disk image which can be viewed with LIST. 85 | 86 | To unmount the D64 file and return to the original device, use 87 | LOAD"$:..",devicenumber 88 | 89 | ## Updating the PETdisk MAX 90 | 91 | Firmware updates will come periodically with fixes and new features. The latest firmware for both the v1 and v2 PETdisk MAX models will be located here:\ 92 | PETdisk MAX v1 (Atmel ATmega1284) 93 | [FIRMWARE.BIN](https://github.com/bitfixer/petdisk-max/raw/main/firmware/FIRMWARE.BIN) 94 | 95 | PETdisk MAX v2 (ESP32): 96 | [FIRMWARE.PD2](https://github.com/bitfixer/petdisk-max/raw/main/firmware/FIRMWARE.PD2) 97 | 98 | To update the firmware on the device, copy this file onto the root directory of an empty microSD card formatted to FAT32. Insert the card into the PETdisk and power up. On the v1, the new firmware will be loaded onto the device after a few seconds. On the v2, the update takes about a minute during which you will first see rapid blinking on the LED, then a single blink every few seconds, followed by a few additional blinks and then the LED remains on. Once the LED is solidly on, the update is done.\ 99 | You can verify that the update worked by loading a directory from the SD card. 100 | At the end of the directory listing the git commit id will be listed, so you can verify it changed from before the update. This also provides a firmware ID which you can use if you need to report any bugs. 101 | 102 | ## Building the PETdisk MAX firmware 103 | 104 | If you want to build the PETdisk MAX firmware, two versions are included in this repo. The first is a legacy version built with platformio and arduino, and is located in the 'legacy' directory. Open that directory in VSCode with the platformio plugin installed, and you should be able to build and install with the platformio menu. 105 | Second is a newer version built directly on esp-idf v5.1+. This is located in the 'idf' directory. With esp-idf 5.1+ installed and sourced, run 'idf.py build flash' to build and install the firmware on the device. 106 | 107 | ## Coming Soon 108 | 109 | Things known to currently not work (but working on it): 110 | 1. Support for BASIC 1 ROM (i.e. non-upgraded original PET 2001) 111 | 2. REL files 112 | 3. U2 (block write) drive command 113 | 114 | Please let me know if you discover any bugs or have feature requests. 115 | bitfixer at (removeforantispam) bitfixer dot com 116 | 117 | 118 | 119 | -------------------------------------------------------------------------------- /firmware/FIRMWARE.BIN: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bitfixer/petdisk-max/7ca0859926249b7c8f7e129c2beb325d5b22a573/firmware/FIRMWARE.BIN -------------------------------------------------------------------------------- /firmware/FIRMWARE.PD2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bitfixer/petdisk-max/7ca0859926249b7c8f7e129c2beb325d5b22a573/firmware/FIRMWARE.PD2 -------------------------------------------------------------------------------- /idf/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # For more information about build system see 2 | # https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/build-system.html 3 | # The following five lines of boilerplate have to be in your project's 4 | # CMakeLists in this exact order for cmake to work correctly 5 | cmake_minimum_required(VERSION 3.16) 6 | 7 | include($ENV{IDF_PATH}/tools/cmake/project.cmake) 8 | project(main) 9 | 10 | include(./scripts/GitHash.cmake) 11 | GetGitHash() -------------------------------------------------------------------------------- /idf/main/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | FILE(GLOB_RECURSE app_sources ${CMAKE_SOURCE_DIR}/main/*.cpp) 2 | 3 | set(components driver freertos hal fatfs esp_wifi nvs_flash esp_http_client console esp_timer esp-fast-gpio) 4 | 5 | idf_component_register(SRCS ${app_sources} 6 | INCLUDE_DIRS "." 7 | REQUIRES ${components} 8 | ) 9 | -------------------------------------------------------------------------------- /idf/main/D64DataSource.h: -------------------------------------------------------------------------------- 1 | #ifndef __d64_datasource_h__ 2 | #define __d64_datasource_h__ 3 | 4 | #include 5 | #include 6 | #include "DataSource.h" 7 | #include "Logger.h" 8 | 9 | // need to mount a file as a d64 filesystem 10 | // the file will be served from another datasource 11 | // needs to support searching for a file and seeking within the file 12 | 13 | #define BLOCK_SIZE 256 14 | #define BAM_SIZE 4*35 15 | #define DISK_TRACKS 40 16 | #define MAX_TRACKS 35 17 | 18 | #define DEL_TYPE 0x80 19 | #define SEQ_TYPE 0x81 20 | #define PRG_TYPE 0x82 21 | #define USR_TYPE 0x83 22 | #define REL_TYPE 0x84 23 | 24 | typedef struct CBMHeader 25 | { 26 | uint8_t nextBlock[2]; 27 | uint8_t dosVersion; 28 | uint8_t unused1; 29 | uint8_t bam[BAM_SIZE]; 30 | uint8_t diskName[16]; 31 | uint8_t id[2]; 32 | uint8_t unused2; // Usually $A0 33 | uint8_t dosType[2]; 34 | uint8_t unused3[4]; // Usually $A0 35 | uint8_t track40Extended[55]; // Usually $00, except for 40 track format 36 | } CBMHeader; 37 | 38 | typedef struct 39 | { 40 | uint8_t nextBlock[2]; // Track and block of next directory 41 | // block. When the first byte is 00 42 | // that is the last block. 43 | 44 | uint8_t fileType; 45 | // 0x80 = DELeted 46 | // 0x81 = SEQuential 47 | // 0x82 = PROGram 48 | // 0x83 = USER 49 | // 0x84 = RELative 50 | 51 | uint8_t dataBlock[2]; // Track and block of first data block 52 | uint8_t fileName[16]; // Filename padded with spaces 53 | uint8_t sideSector[2]; // Relative only track and block first side 54 | // sector. 55 | 56 | uint8_t recordSize; // Relative file only. Record Size. 57 | uint8_t unused[6]; // Unused bytes 58 | 59 | uint8_t fileSize[2]; // Number of blocks in file. Low Byte, High Byte. 60 | } CBMFile_Entry; 61 | 62 | typedef struct 63 | { 64 | CBMFile_Entry *file; 65 | int files; 66 | } CBMDirectory; 67 | 68 | typedef struct 69 | { 70 | CBMHeader header; 71 | CBMDirectory directory; 72 | } CBMDisk; 73 | 74 | // ERROR CODES 75 | #define D64_FILE_ERROR -1 76 | #define D64_OUT_OF_MEMORY -2 77 | #define D64_OUT_OF_RANGE -3 78 | #define D64_FILE_NOT_FOUND -4 79 | #define D64_ERROR -5 80 | #define D64_FILE_NOT_OPEN -6 81 | #define D64_FILE_EXISTS -7 82 | 83 | class D64DataSource : public DataSource 84 | { 85 | public: 86 | D64DataSource() {} 87 | ~D64DataSource() {} 88 | 89 | bool init() 90 | { 91 | return true; 92 | } 93 | 94 | bool initWithDataSource(DataSource* dataSource, const char* fileName, Logger* logger); 95 | 96 | void openFileForWriting(uint8_t* fileName); 97 | bool openFileForReading(uint8_t* fileName); 98 | uint32_t seek(uint32_t position); 99 | 100 | bool openDirectory(const char* dirName); 101 | uint16_t getNextFileBlock(); 102 | bool isLastBlock(); 103 | bool getNextDirectoryEntry(); 104 | bool isInitialized(); 105 | 106 | void writeBufferToFile(uint16_t numBytes); 107 | void closeFile(); 108 | void openCurrentDirectory(); 109 | uint8_t* getFilename(); 110 | uint8_t* getBuffer(); 111 | uint16_t writeBufferSize(); 112 | uint16_t readBufferSize(); 113 | void processCommandString(int* address); 114 | 115 | DataSource* getFileDataSource(); 116 | 117 | private: 118 | DataSource* _fileDataSource; 119 | CBMFile_Entry* _currentFileEntry; 120 | uint8_t _fileName[21]; 121 | uint8_t* _cbmBuffer; 122 | uint32_t* _cbmTrackLayout; 123 | uint8_t _dirTrackBlock[2]; 124 | uint8_t _fileTrackBlock[2]; 125 | uint8_t _fileFirstTrackBlock[2]; 126 | uint8_t _dirIndexInBuffer; 127 | uint8_t _cbmBAM[BAM_SIZE]; 128 | uint16_t _blocksInFile; 129 | bool _directBlockAccess; 130 | Logger* _logger; 131 | 132 | void prepareNextBlockForWriting(); 133 | 134 | void cbmMount(); 135 | void cbmPrintHeader(CBMDisk* disk); 136 | CBMHeader* cbmLoadHeader(); 137 | void cbmSaveHeader(); 138 | uint32_t cbmBlockLocation(uint8_t* tb); 139 | uint8_t* cbmReadBlock(uint8_t* tb); 140 | void cbmWriteBlock(uint8_t* tb); 141 | uint8_t* cbmEmptyBlockChain(CBMDisk* disk); 142 | void cbmPrintFileEntry(CBMFile_Entry* entry); 143 | CBMFile_Entry* cbmGetNextFileEntry(); 144 | CBMFile_Entry* cbmSearch(uint8_t* searchNameA, uint8_t fileType); 145 | uint8_t* cbmD64StringCString(uint8_t* dest, const uint8_t* source); 146 | uint8_t* cbmCopyString(uint8_t* dest, const uint8_t* source); 147 | bool cbmFindEmptyBlock(uint8_t* tb); 148 | uint8_t cbmSectorsPerTrack(uint8_t track); 149 | bool cbmIsBlockFree(uint8_t* tb); 150 | int cbmBAM(uint8_t *tb, char s); 151 | void cbmCreateFileEntry(uint8_t* fileName, uint8_t fileType, uint16_t blocksInFile); 152 | bool findEmptyDirectoryBlock(uint8_t* tb); 153 | bool createNewDirectoryBlock(uint8_t* tb); 154 | 155 | }; 156 | 157 | #endif -------------------------------------------------------------------------------- /idf/main/DataSource.h: -------------------------------------------------------------------------------- 1 | #ifndef __datasource_h__ 2 | #define __datasource_h__ 3 | 4 | #include 5 | 6 | class DataSource 7 | { 8 | public: 9 | DataSource() {} 10 | ~DataSource() {} 11 | 12 | virtual bool init() = 0; 13 | virtual void openFileForWriting(uint8_t* fileName) = 0; 14 | virtual bool openFileForReading(uint8_t* fileName) = 0; 15 | virtual bool openDirectory(const char* dirName) = 0; 16 | virtual uint16_t getNextFileBlock() = 0; 17 | virtual bool isLastBlock() = 0; 18 | virtual bool getNextDirectoryEntry() = 0; 19 | virtual bool isInitialized() = 0; 20 | virtual void writeBufferToFile(uint16_t numBytes) = 0; 21 | virtual void updateBlock() {} 22 | virtual void closeFile() = 0; 23 | virtual void openCurrentDirectory() = 0; 24 | virtual uint32_t seek(uint32_t pos) { return 0; } 25 | virtual bool isHidden() { return false; } 26 | virtual bool isVolumeId() { return false; } 27 | virtual bool isDirectory() { return false; } 28 | virtual uint8_t* getFilename() = 0; 29 | virtual uint8_t* getBuffer() = 0; 30 | virtual uint16_t writeBufferSize() = 0; 31 | virtual uint16_t readBufferSize() { return 512; } 32 | virtual uint16_t requestReadBufferSize(uint16_t requestedReadBufferSize) { 33 | // default to not changing read buffer size 34 | return 512; 35 | } 36 | virtual uint16_t requestWriteBufferSize(uint16_t requestedWriteBufferSize) { 37 | return 512; 38 | } 39 | 40 | virtual void processCommandString(int* address) {} // default no action 41 | virtual bool needRealTime() { return false; } 42 | virtual void setDateTime(int year, int month, int day, int hour, int minute, int second) {} 43 | }; 44 | 45 | #endif -------------------------------------------------------------------------------- /idf/main/EspConn.h: -------------------------------------------------------------------------------- 1 | #ifndef __esp_conn_h__ 2 | #define __esp_conn_h__ 3 | 4 | #include 5 | #include 6 | 7 | namespace bitfixer 8 | { 9 | 10 | class EspConn { 11 | public: 12 | EspConn() 13 | : _serialBuffer(NULL) 14 | , _serialBufferSize(NULL) 15 | { 16 | 17 | } 18 | 19 | bool initWithParams(uint8_t* buffer, uint16_t* bufferSize); 20 | bool connect(const char* ssid, const char* passphrase); 21 | bool startClient(const char* host, uint16_t port); 22 | void sendData(uint8_t sock, unsigned char* data, int len); 23 | bool isConnected(); 24 | private: 25 | 26 | uint8_t* _serialBuffer; 27 | uint16_t* _serialBufferSize; 28 | 29 | char _host[256]; 30 | int _port; 31 | 32 | bool _connected = false; 33 | 34 | bool wifi_start(); 35 | bool wifi_stop(); 36 | }; 37 | 38 | } 39 | 40 | #endif -------------------------------------------------------------------------------- /idf/main/EspHttp.cpp: -------------------------------------------------------------------------------- 1 | #include "EspHttp.h" 2 | #include 3 | #include 4 | #include 5 | #include "hardware.h" 6 | #include "helpers.h" 7 | #include "base64.hpp" 8 | 9 | namespace bitfixer { 10 | 11 | void EspHttp::initWithParams(EspConn* espConn) 12 | { 13 | _espConn = espConn; 14 | } 15 | 16 | bool EspHttp::postBlock(char* host, int port, char* url, char* params, uint8_t* buffer, uint16_t* bufferSize, int numBytes) 17 | { 18 | int encoded_len = base64_len(numBytes); 19 | urlInfo* info = (urlInfo*)buffer; 20 | sprintf((char*)sendBuffer, "PUT %s%s&b64=1 HTTP/1.0\r\nHost: %s\r\nContent-Length: %d\r\n\r\n", url, params, host, encoded_len); 21 | int s = strlen((const char*)sendBuffer); 22 | uint8_t* dataStart = &sendBuffer[s]; 23 | int full_data_length = s + base64_encode((uint8_t*)info->blockData, numBytes, dataStart); 24 | 25 | if (!_espConn->startClient(host, port)) 26 | { 27 | // error 28 | return false; 29 | } 30 | _espConn->sendData(0, sendBuffer, full_data_length); 31 | return true; 32 | } 33 | 34 | //#define REQUEST_HASH 1 35 | 36 | #ifdef REQUEST_HASH 37 | #define get16bits(d) ((((uint32_t)(((const uint8_t *)(d))[1])) << 8)\ 38 | +(uint32_t)(((const uint8_t *)(d))[0]) ) 39 | 40 | uint32_t SuperFastHash (const char * data, int len) { 41 | uint32_t hash = len, tmp; 42 | int rem; 43 | 44 | if (len <= 0 || data == NULL) return 0; 45 | 46 | rem = len & 3; 47 | len >>= 2; 48 | 49 | /* Main loop */ 50 | for (;len > 0; len--) { 51 | hash += get16bits (data); 52 | tmp = (get16bits (data+2) << 11) ^ hash; 53 | hash = (hash << 16) ^ tmp; 54 | data += 2*sizeof (uint16_t); 55 | hash += hash >> 11; 56 | } 57 | 58 | /* Handle end cases */ 59 | switch (rem) { 60 | case 3: hash += get16bits (data); 61 | hash ^= hash << 16; 62 | hash ^= ((signed char)data[sizeof (uint16_t)]) << 18; 63 | hash += hash >> 11; 64 | break; 65 | case 2: hash += get16bits (data); 66 | hash ^= hash << 11; 67 | hash += hash >> 17; 68 | break; 69 | case 1: hash += (signed char)*data; 70 | hash ^= hash << 10; 71 | hash += hash >> 1; 72 | } 73 | 74 | /* Force "avalanching" of final 127 bits */ 75 | hash ^= hash << 3; 76 | hash += hash >> 5; 77 | hash ^= hash << 4; 78 | hash += hash >> 17; 79 | hash ^= hash << 25; 80 | hash += hash >> 6; 81 | 82 | return hash; 83 | } 84 | #endif 85 | 86 | uint8_t* EspHttp::makeRequest(const char* host, int port, const char* url, const char* params, uint8_t* buffer, uint16_t* bufferSize, int* size) 87 | { 88 | urlInfo* info = (urlInfo*)buffer; 89 | char* data = info->urlstring; 90 | 91 | sprintf_P(data, PSTR("GET %s%s HTTP/1.0\r\nHost: %s\r\n\r\n"), url, params, host); 92 | if (!_espConn->startClient(host, port)) 93 | { 94 | return NULL; 95 | } 96 | _espConn->sendData(0, (unsigned char*)data, strlen(data)); 97 | int bufSize = *bufferSize; 98 | 99 | // parse data from serial buffer 100 | // find beginning of HTTP message 101 | uint8_t* httpStart = (uint8_t*)bf_memmem(buffer, bufSize, "HTTP", 4); 102 | if (httpStart == 0) 103 | { 104 | *size = 0; 105 | return 0; 106 | } 107 | 108 | int httpSize = bufSize - (httpStart - buffer); 109 | 110 | // find blank newline to signify beginning of payload data 111 | uint8_t* datastart = (uint8_t*)bf_memmem(httpStart, httpSize, "\r\n\r\n", 4); 112 | 113 | if (datastart == 0) 114 | { 115 | *size = -1; 116 | return 0; 117 | } 118 | 119 | datastart += 4; 120 | *size = bufSize - (datastart - buffer); 121 | 122 | #ifdef REQUEST_HASH 123 | uint32_t hash = SuperFastHash((const char*)datastart, *size); 124 | log_i("hash %04lX", hash); 125 | #endif 126 | 127 | return datastart; 128 | } 129 | 130 | uint32_t EspHttp::getSize(const char* host, int port, const char* url, uint8_t* buffer, uint16_t* bufferSize) 131 | { 132 | uint8_t* datastart; 133 | uint32_t fileSize; 134 | int size; 135 | datastart = makeRequest(host, port, url, "&l=1", buffer, bufferSize, &size); 136 | if (datastart == NULL) 137 | { 138 | return 0; 139 | } 140 | 141 | sscanf((const char*)datastart, "%" SCNu32 "\r\n", &fileSize); 142 | return fileSize; 143 | } 144 | 145 | uint8_t* EspHttp::getRange(const char* host, int port, const char* url, uint32_t start, uint32_t end, uint8_t* buffer, uint16_t* bufferSize, int* size) 146 | { 147 | char params[25]; 148 | sprintf_P(params, PSTR("&s=%" PRIu32 "&e=%" PRIu32), start, end); 149 | return makeRequest(host, port, url, (const char*)params, buffer, bufferSize, size); 150 | } 151 | 152 | } -------------------------------------------------------------------------------- /idf/main/EspHttp.h: -------------------------------------------------------------------------------- 1 | #ifndef __esp_http_h__ 2 | #define __esp_http_h__ 3 | 4 | #include "EspConn.h" 5 | #include 6 | 7 | namespace bitfixer 8 | { 9 | 10 | struct __attribute__ ((packed)) urlInfo { 11 | char host[64]; 12 | char url[64]; 13 | char params[64]; 14 | char urlstring[256]; 15 | char blockData[512]; 16 | char fileName[64]; 17 | }; 18 | 19 | class EspHttp 20 | { 21 | public: 22 | EspHttp() 23 | : _espConn(NULL) 24 | {} 25 | 26 | EspHttp(EspConn* espConn) 27 | : _espConn(espConn) 28 | {} 29 | 30 | ~EspHttp() {} 31 | 32 | void initWithParams(EspConn* espConn); 33 | bool postBlock(char* host, int port, char* url, char* params, uint8_t* buffer, uint16_t* bufferSize, int numBytes); 34 | uint8_t* makeRequest(const char* host, int port, const char* url, const char* params, uint8_t* buffer, uint16_t* bufferSize, int* size); 35 | uint32_t getSize(const char* host, int port, const char* url, uint8_t* buffer, uint16_t* bufferSize); 36 | uint8_t* getRange(const char* host, int port, const char* url, uint32_t start, uint32_t end, uint8_t* buffer, uint16_t* bufferSize, int* size); 37 | 38 | int getSizeE(const char* host, const char* url, uint8_t* buffer, uint16_t* bufferSize); 39 | 40 | private: 41 | EspConn* _espConn; 42 | 43 | uint8_t sendBuffer[2048]; 44 | }; 45 | 46 | } 47 | 48 | #endif -------------------------------------------------------------------------------- /idf/main/FAT32.h: -------------------------------------------------------------------------------- 1 | /* 2 | FAT32.h 3 | FAT32 filesystem Routines in the PETdisk storage device 4 | Copyright (C) 2011 Michael Hill 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | 19 | Contact the author at bitfixer@bitfixer.com 20 | http://bitfixer.com 21 | */ 22 | 23 | #ifndef _FAT32_H_ 24 | #define _FAT32_H_ 25 | 26 | #include "SD_routines.h" 27 | #include "DataSource.h" 28 | #include "helpers.h" 29 | #include 30 | 31 | //Structure to access Directory Entry in the FAT 32 | struct PACKED dir_Structure{ 33 | uint8_t name[11]; //0 34 | uint8_t attrib; //11 //file attributes 35 | uint8_t NTreserved; //12 //always 0 36 | uint8_t timeTenth; //13 //tenths of seconds, set to 0 here 37 | uint16_t createTime; //14 //time file was created 38 | uint16_t createDate; //16 //date file was created 39 | uint16_t lastAccessDate;//18 40 | uint16_t firstClusterHI;//20 //higher word of the first cluster number 41 | uint16_t writeTime; //22 //time of last write 42 | uint16_t writeDate; //24 //date of last write 43 | uint16_t firstClusterLO;//26 //lower word of the first cluster number 44 | uint32_t fileSize; //28 //size of file in bytes 45 | //32 46 | }; 47 | 48 | struct PACKED dir_Longentry_Structure{ 49 | uint8_t LDIR_Ord; 50 | uint16_t LDIR_Name1[5]; 51 | uint8_t LDIR_Attr; 52 | uint8_t LDIR_Type; 53 | uint8_t LDIR_Chksum; 54 | uint16_t LDIR_Name2[6]; 55 | uint16_t LDIR_FstClusLO; 56 | uint16_t LDIR_Name3[2]; 57 | }; 58 | 59 | // structure for file read information 60 | typedef struct PACKED _file_stat{ 61 | uint32_t currentCluster; 62 | uint32_t fileSize; 63 | uint32_t currentSector; 64 | uint32_t byteCounter; 65 | int sectorIndex; 66 | } file_stat; 67 | 68 | typedef struct PACKED _file_position { 69 | uint8_t isLongFilename; 70 | uint8_t *fileName; 71 | uint32_t startCluster; 72 | uint32_t cluster; 73 | uint32_t dirStartCluster; 74 | uint8_t sectorIndex; 75 | uint32_t sector; 76 | uint32_t fileSize; 77 | uint32_t byteCounter; 78 | uint16_t byte; 79 | uint8_t shortFilename[11]; 80 | } file_position; 81 | 82 | #define MAX_FILENAME 256 83 | 84 | namespace bitfixer { 85 | 86 | class FAT32 : public DataSource 87 | { 88 | public: 89 | FAT32() 90 | : _sd(NULL) 91 | , _FatBuffer(NULL) 92 | , _longEntryString(NULL) 93 | , _currentDirectoryEntry(0) 94 | , _initialized(false) 95 | , _rootCluster(0) 96 | , _timeValue(0) 97 | , _dateValue(0) 98 | { 99 | 100 | } 101 | 102 | FAT32(SD* sd, uint8_t* fatbuffer, uint8_t* longEntryBuffer) 103 | : _sd(sd) 104 | , _FatBuffer(fatbuffer) 105 | , _longEntryString(longEntryBuffer) 106 | , _currentDirectoryEntry(0) 107 | , _initialized(false) 108 | , _rootCluster(0) 109 | , _timeValue(0) 110 | , _dateValue(0) 111 | { 112 | 113 | } 114 | 115 | ~FAT32() {} 116 | 117 | bool initWithParams(SD* sd, uint8_t* fatbuffer, uint8_t* longEntryBuffer); 118 | bool init(); 119 | bool isInitialized(); 120 | uint8_t* getLongEntryString(); 121 | 122 | void openDirectory(uint32_t firstCluster); 123 | bool getNextDirectoryEntry(); 124 | bool openFileForReading(uint8_t *fileName); 125 | uint32_t getFileSize(); 126 | uint16_t getNextFileBlock(); 127 | bool isLastBlock(); 128 | 129 | void openFileForWriting(uint8_t *fileName); 130 | void writeBufferToFile(uint16_t bytesToWrite); 131 | void updateBlock(); 132 | void closeFile(); 133 | bool isLongFilename(); 134 | bool isHidden(); 135 | bool isVolumeId(); 136 | bool isDirectory(); 137 | uint8_t* getFilename(); 138 | bool openDirectory(const char* dirName); 139 | void openCurrentDirectory(); 140 | uint8_t* getBuffer(); 141 | 142 | bool findFile(char* fileName); 143 | void deleteFile(); 144 | uint32_t seek(uint32_t pos); 145 | 146 | void setDateTime(int year, int month, int day, int hour, int minute, int second); 147 | 148 | uint16_t writeBufferSize() 149 | { 150 | return 512; 151 | } 152 | 153 | bool needRealTime() 154 | { 155 | return true; 156 | } 157 | 158 | private: 159 | SD* _sd; 160 | uint8_t* _FatBuffer; 161 | uint8_t* _longEntryString; 162 | file_position _filePosition; 163 | struct dir_Structure* _currentDirectoryEntry; 164 | bool _initialized; 165 | 166 | bool _indexed; 167 | uint32_t _fileClusterIndex[64]; 168 | 169 | uint32_t _firstDataSector; 170 | uint32_t _rootCluster; 171 | 172 | uint16_t _timeValue; 173 | uint16_t _dateValue; 174 | 175 | uint32_t _totalClusters; 176 | uint16_t _bytesPerSector; 177 | uint16_t _sectorPerCluster; 178 | uint16_t _reservedSectorCount; 179 | uint32_t _unusedSectors; 180 | uint32_t _appendFileSector; 181 | uint32_t _appendFileLocation; 182 | uint32_t _fileSize; 183 | uint32_t _appendStartCluster; 184 | 185 | //flag to keep track of free cluster count updating in FSinfo sector 186 | uint8_t _freeClusterCountUpdated; 187 | uint32_t _fileStartCluster; 188 | 189 | uint32_t _currentDirectoryCluster; 190 | 191 | uint32_t getRootCluster(); 192 | uint8_t getBootSectorData (void); 193 | uint32_t getFirstSector(uint32_t clusterNumber); 194 | uint32_t getSetFreeCluster(uint8_t totOrNext, uint8_t get_set, uint32_t FSEntry); 195 | 196 | uint32_t getSetNextCluster (uint32_t clusterNumber,uint8_t get_set,uint32_t clusterEntry); 197 | uint8_t readFile (uint8_t flag, uint8_t *fileName); 198 | 199 | void convertToShortFilename(uint8_t *input, uint8_t *output); 200 | void writeFile (uint8_t *fileName); 201 | uint32_t searchNextFreeCluster (uint32_t startCluster); 202 | void freeMemoryUpdate (uint8_t flag, uint32_t size); 203 | 204 | void startFileRead(struct dir_Structure *dirEntry, file_stat *thisFileStat); 205 | void getCurrentFileBlock(file_stat *thisFileStat); 206 | uint32_t getNextBlockAddress(file_stat *thisFileStat); 207 | 208 | uint32_t getFirstCluster(struct dir_Structure *dir); 209 | void makeShortFilename(uint8_t *longFilename, uint8_t *shortFilename); 210 | 211 | uint8_t ChkSum (uint8_t *pFcbName); 212 | uint8_t isLongFilename(uint8_t *fileName); 213 | uint8_t numCharsToCompare(uint8_t *fileName, uint8_t maxChars); 214 | 215 | bool findFile(char* fileName, uint32_t firstCluster); 216 | void indexFileForSeeking(); 217 | 218 | void copyShortFilename(); 219 | }; 220 | 221 | } 222 | 223 | #endif 224 | -------------------------------------------------------------------------------- /idf/main/HTTPClient.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | void http_native_request(void* args); -------------------------------------------------------------------------------- /idf/main/HTTPDataSource.cpp: -------------------------------------------------------------------------------- 1 | #include "HTTPDataSource.h" 2 | #include 3 | #include "http.h" 4 | #include "console.h" 5 | 6 | namespace bitfixer { 7 | 8 | static const char* TAG = "HTTPDS"; 9 | 10 | bool HTTPDataSource::openFileForReading(uint8_t* fileName) { 11 | ESP_LOGI(TAG, "open file for reading: %s", (char*)fileName); 12 | 13 | // fetch entire file 14 | char str[256]; 15 | sprintf(str, "http://bitfixer.com/pd/petdisk.php?file=%s", fileName); 16 | 17 | int size = 64*1024; 18 | ESP_LOGI(TAG, "url is: %s, bufsize %d", str, size); 19 | 20 | int length = HTTP::request(str, _file_buffer, size); 21 | ESP_LOGI(TAG, "result: %d", length); 22 | 23 | _file_pos = -1; 24 | if (length > 0) { 25 | _file_size = length; 26 | } else { 27 | _file_size = -1; 28 | } 29 | 30 | return (bool)(length > 0); 31 | } 32 | 33 | uint16_t HTTPDataSource::getNextFileBlock() { 34 | if (_file_pos == -1) { 35 | _file_pos = 0; 36 | } else { 37 | _file_pos += readBufferSize(); 38 | } 39 | 40 | int block_size = readBufferSize(); 41 | int rem = _file_size - _file_pos; 42 | if (block_size > rem) { 43 | block_size = rem; 44 | } 45 | 46 | memcpy(_buffer, &_file_buffer[_file_pos], block_size); 47 | return (uint16_t)block_size; 48 | } 49 | 50 | bool HTTPDataSource::isLastBlock() { 51 | int next_pos = 0; 52 | if (_file_pos >= 0) { 53 | next_pos = _file_pos + readBufferSize(); 54 | } 55 | if (next_pos >= _file_size) { 56 | return true; 57 | } 58 | return false; 59 | } 60 | 61 | 62 | } -------------------------------------------------------------------------------- /idf/main/HTTPDataSource.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "DataSource.h" 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | namespace bitfixer { 10 | 11 | class HTTPDataSource : public DataSource { 12 | public: 13 | HTTPDataSource() { 14 | _buffer = (uint8_t*)malloc(512); 15 | _file_buffer = (uint8_t*)malloc(64*1024); 16 | } 17 | ~HTTPDataSource() { 18 | if (_buffer) { 19 | free(_buffer); 20 | } 21 | 22 | if (_file_buffer) { 23 | free(_file_buffer); 24 | } 25 | } 26 | 27 | virtual bool init() override { return true; } 28 | virtual void openFileForWriting(uint8_t* fileName) override {} 29 | virtual bool openFileForReading(uint8_t* fileName) override; 30 | virtual bool openDirectory(const char* dirName) override { return true; } 31 | virtual uint16_t getNextFileBlock() override; 32 | virtual bool isLastBlock() override; 33 | virtual bool getNextDirectoryEntry() override { return true; } 34 | virtual bool isInitialized() { 35 | return true; 36 | }; 37 | virtual void writeBufferToFile(uint16_t numBytes) override {} 38 | virtual void updateBlock() override {} 39 | virtual void closeFile() override {} 40 | virtual void openCurrentDirectory() override {} 41 | 42 | virtual uint8_t* getFilename() override { return nullptr; } 43 | virtual uint8_t* getBuffer() override { 44 | return _buffer; 45 | } 46 | virtual uint16_t writeBufferSize() override { 47 | return 512; 48 | }; 49 | 50 | private: 51 | uint8_t* _buffer = nullptr; 52 | uint8_t* _file_buffer = nullptr; 53 | int _file_size = -1; 54 | int _file_pos = -1; 55 | }; 56 | 57 | } -------------------------------------------------------------------------------- /idf/main/IEEE488.h: -------------------------------------------------------------------------------- 1 | /* 2 | IEEE488.h 3 | IEEE Routines in the PETdisk storage device 4 | Copyright (C) 2011 Michael Hill 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | 19 | Contact the author at bitfixer@bitfixer.com 20 | http://bitfixer.com 21 | */ 22 | 23 | #ifndef _IEEE488_H 24 | #define _IEEE488_H 25 | 26 | #include 27 | #include 28 | 29 | #define TALK 0x40 30 | #define LISTEN 0x20 31 | 32 | #define UNTALK 0x5F 33 | #define UNLISTEN 0x3F 34 | 35 | typedef enum { 36 | ATN = 0x01, 37 | NDAC = 0x02, 38 | DAV = 0x04, 39 | NRFD = 0x08, 40 | EOI = 0x10 41 | } IEEEBusSignal; 42 | 43 | namespace bitfixer { 44 | 45 | class IEEE488 { 46 | public: 47 | IEEE488() 48 | : _atn_low(false) 49 | , _eoi_low(false) 50 | , _unlistened(false) 51 | {} 52 | 53 | ~IEEE488() {} 54 | 55 | void init(); 56 | void sendIEEEBytes(uint8_t *entry, int size, uint8_t isLast); 57 | uint8_t sendIEEEByteCheckForATN(uint8_t byte); 58 | uint8_t sendIEEEByteCheckForATN2(uint8_t byte, bool last); 59 | void unlisten(); 60 | bool is_unlistened(); 61 | void begin_output(); 62 | 63 | void begin_output_start(); 64 | void begin_output_end(); 65 | 66 | void end_output(); 67 | 68 | uint8_t get_byte_from_bus(); 69 | void acknowledge_bus_byte(); 70 | bool atn_is_low(); 71 | bool eoi_is_low(); 72 | void signal_ready_for_data(); 73 | 74 | void raise_dav_and_eoi(); 75 | uint8_t wait_for_ndac_low_or_atn_low(); 76 | IEEEBusSignal wait_for_ndac_high_or_atn_low(); 77 | uint8_t wait_for_nrfd_high_or_atn_low(); 78 | void wait_for_atn_low(); 79 | void wait_for_dav_low(); 80 | void recv_byte(uint8_t *byte); 81 | 82 | uint8_t get_device_address(uint8_t* dir, bool* success); 83 | void accept_address(); 84 | void reject_address(); 85 | 86 | void write_byte_to_data_bus(uint8_t byte); 87 | 88 | static IEEE488* get_instance(); 89 | private: 90 | bool _atn_low; 91 | bool _eoi_low; 92 | 93 | bool _unlistened; 94 | 95 | void wait_for_atn_high(); 96 | void wait_for_atn_high_with_timeout(int timeout_us); 97 | void wait_for_dav_high(); 98 | 99 | void wait_for_nrfd_high(); 100 | void wait_for_nrfd_low(); 101 | void wait_for_ndac_high(); 102 | void wait_for_ndac_low(); 103 | void send_byte(uint8_t byte, int last); 104 | 105 | }; 106 | 107 | } 108 | 109 | #endif -------------------------------------------------------------------------------- /idf/main/Logger.h: -------------------------------------------------------------------------------- 1 | #ifndef __logger_h__ 2 | #define __logger_h__ 3 | 4 | #include 5 | #include 6 | 7 | #define LOG_BUFFER_SIZE 64 8 | static char _line[LOG_BUFFER_SIZE]; 9 | 10 | class Logger { 11 | public: 12 | Logger() {} 13 | ~Logger() {} 14 | 15 | virtual void init() {} 16 | virtual void log(const char* str) {} 17 | virtual void log(unsigned char* data, int length) {} 18 | virtual void logF(const char* str) {} 19 | virtual void printf(const char* format, ...) 20 | { 21 | va_list vl; 22 | va_start(vl, format); 23 | vsprintf(_line, format, vl); 24 | log(_line); 25 | } 26 | virtual void flush() {} 27 | }; 28 | 29 | #endif -------------------------------------------------------------------------------- /idf/main/NetworkDataSource.h: -------------------------------------------------------------------------------- 1 | #ifndef __network_data_source_h__ 2 | #define __network_data_source_h__ 3 | 4 | #include "DataSource.h" 5 | #include "EspHttp.h" 6 | #include "Settings.h" 7 | 8 | namespace bitfixer { 9 | 10 | class NetworkDataSource : public DataSource 11 | { 12 | public: 13 | NetworkDataSource() 14 | : _http(NULL) 15 | , _fileSize(0) 16 | , _currentBlockByte(0) 17 | , _currentOutputByte(0) 18 | , _currentDirectoryPage(0) 19 | , _blockData(0) 20 | , _dataBuffer(NULL) 21 | , _dataBufferSize(NULL) 22 | , _dirPtr(0) 23 | , _firstBlockWritten(false) 24 | , _readBufferSize(512) 25 | , _writeBufferSize(512) 26 | {} 27 | 28 | NetworkDataSource(EspHttp* http, uint8_t* buffer, uint16_t* bufferSize) 29 | : _http(http) 30 | , _fileSize(0) 31 | , _currentBlockByte(0) 32 | , _currentOutputByte(0) 33 | , _currentDirectoryPage(0) 34 | , _blockData(0) 35 | , _dataBuffer(buffer) 36 | , _dataBufferSize(bufferSize) 37 | , _dirPtr(0) 38 | , _firstBlockWritten(false) 39 | , _readBufferSize(512) 40 | , _writeBufferSize(512) 41 | { 42 | struct urlInfo* urlInfo = (struct urlInfo*)_dataBuffer; 43 | _fileName = urlInfo->fileName; 44 | } 45 | 46 | ~NetworkDataSource() {} 47 | 48 | void initWithParams(EspHttp* http, uint8_t* buffer, uint16_t* bufferSize) 49 | { 50 | _http = http; 51 | _dataBuffer = buffer; 52 | _dataBufferSize = bufferSize; 53 | 54 | struct urlInfo* urlInfo = (struct urlInfo*)_dataBuffer; 55 | _fileName = urlInfo->fileName; 56 | } 57 | 58 | void setUrlData(void* eepromHost, int eepromHostLength, int port, void* eepromUrl, int eepromUrlLength) 59 | { 60 | _settings.initWithParams(eepromHost, eepromHostLength, port, eepromUrl, eepromUrlLength); 61 | } 62 | 63 | bool init(); 64 | bool isInitialized(); 65 | void openFileForWriting(unsigned char* fileName); 66 | bool openFileForReading(unsigned char* fileName); 67 | bool openDirectory(const char* dirName); 68 | uint16_t getNextFileBlock(); 69 | bool isLastBlock(); 70 | bool getNextDirectoryEntry(); 71 | 72 | void writeBufferToFile(uint16_t numBytes); 73 | void updateBlock(); 74 | void closeFile(); 75 | void openCurrentDirectory(); 76 | bool isDirectory() { return false; } 77 | unsigned char* getFilename(); 78 | unsigned char* getBuffer(); 79 | 80 | bool getCurrentDateTime(int* year, int* month, int* day, int* hour, int* minute, int* second); 81 | 82 | uint32_t seek(uint32_t pos); 83 | 84 | uint16_t readBufferSize() 85 | { 86 | return _readBufferSize; 87 | } 88 | 89 | uint16_t writeBufferSize() 90 | { 91 | return _writeBufferSize; 92 | } 93 | 94 | uint16_t requestReadBufferSize(uint16_t requestedReadBufferSize); 95 | uint16_t requestWriteBufferSize(uint16_t requestedWriteBufferSize); 96 | 97 | Settings _settings; 98 | private: 99 | EspHttp* _http; 100 | uint32_t _fileSize; 101 | uint32_t _currentBlockByte; 102 | uint32_t _currentOutputByte; 103 | int _currentDirectoryPage; 104 | uint8_t* _blockData; 105 | uint8_t* _dataBuffer; 106 | uint16_t* _dataBufferSize; 107 | char* _fileName; 108 | uint8_t* _dirPtr; 109 | bool _firstBlockWritten; 110 | 111 | uint16_t _readBufferSize; 112 | uint16_t _writeBufferSize; 113 | 114 | bool fetchBlock(uint32_t start, uint32_t end); 115 | void copyUrlEscapedString(char* dest, char* src); 116 | }; 117 | 118 | } 119 | 120 | #endif -------------------------------------------------------------------------------- /idf/main/SD_routines.h: -------------------------------------------------------------------------------- 1 | /* 2 | sd_routines.h 3 | SD Routines in the PETdisk storage device 4 | Copyright (C) 2011 Michael Hill 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | 19 | Contact the author at bitfixer@bitfixer.com 20 | http://bitfixer.com 21 | 22 | */ 23 | #ifndef _SD_ROUTINES_H_ 24 | #define _SD_ROUTINES_H_ 25 | 26 | #include 27 | #include "SPI_routines.h" 28 | 29 | //Use following macro if you don't want to activate the multiple block access functions 30 | //those functions are not required for FAT32 31 | 32 | #define FAT_TESTING_ONLY 33 | 34 | //SD commands, many of these are not used here 35 | #define GO_IDLE_STATE 0 36 | #define SEND_OP_COND 1 37 | #define SEND_IF_COND 8 38 | #define SEND_CSD 9 39 | #define STOP_TRANSMISSION 12 40 | #define SEND_STATUS 13 41 | #define SET_BLOCK_LEN 16 42 | #define READ_SINGLE_BLOCK 17 43 | #define READ_MULTIPLE_BLOCKS 18 44 | #define WRITE_SINGLE_BLOCK 24 45 | #define WRITE_MULTIPLE_BLOCKS 25 46 | #define ERASE_BLOCK_START_ADDR 32 47 | #define ERASE_BLOCK_END_ADDR 33 48 | #define ERASE_SELECTED_BLOCKS 38 49 | #define SD_SEND_OP_COND 41 //ACMD 50 | #define APP_CMD 55 51 | #define READ_OCR 58 52 | #define CRC_ON_OFF 59 53 | 54 | #define ON 1 55 | #define OFF 0 56 | 57 | class SD 58 | { 59 | public: 60 | SD() 61 | : _spi(NULL) 62 | , _startBlock(0) 63 | , _totalBlocks(0) 64 | , _SDHC_flag(0) 65 | , _cardType(0) 66 | , _cs(0) 67 | { 68 | 69 | } 70 | 71 | SD(bSPI* spi, int cs) 72 | : _spi(spi) 73 | , _startBlock(0) 74 | , _totalBlocks(0) 75 | , _SDHC_flag(0) 76 | , _cardType(0) 77 | , _cs(cs) 78 | { 79 | } 80 | 81 | ~SD() 82 | { 83 | _spi = 0; 84 | } 85 | 86 | uint8_t init(); 87 | uint8_t initWithSPI(bSPI* spi, int cs); 88 | uint8_t sendCommand(uint8_t cmd, uint32_t arg); 89 | uint8_t readSingleBlock(uint32_t startBlock, uint8_t* buffer); 90 | uint8_t writeSingleBlock(uint32_t startBlock, uint8_t* buffer); 91 | 92 | private: 93 | bSPI* _spi; 94 | uint32_t _startBlock; 95 | uint32_t _totalBlocks; 96 | uint8_t _SDHC_flag; 97 | uint8_t _cardType; 98 | int _cs; 99 | 100 | void cs_select(); 101 | void cs_unselect(); 102 | 103 | }; 104 | 105 | #endif 106 | -------------------------------------------------------------------------------- /idf/main/SPI_routines.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | SPI_routines.c 3 | SPI Routines in the PETdisk storage device 4 | Copyright (C) 2011 Michael Hill 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | 19 | Contact the author at bitfixer@bitfixer.com 20 | http://bitfixer.com 21 | */ 22 | #include "SPI_routines.h" 23 | #include "hardware.h" 24 | 25 | void bSPI::init() 26 | { 27 | spi_init(); 28 | } 29 | 30 | uint8_t bSPI::transmit(uint8_t data) 31 | { 32 | return spi_transmit(data); 33 | } 34 | 35 | uint8_t bSPI::receive() 36 | { 37 | return transmit(0xff); 38 | } 39 | 40 | void bSPI::cs_select() 41 | { 42 | spi_cs_select(); 43 | } 44 | 45 | void bSPI::cs_unselect() 46 | { 47 | spi_cs_unselect(); 48 | } 49 | -------------------------------------------------------------------------------- /idf/main/SPI_routines.h: -------------------------------------------------------------------------------- 1 | #ifndef _SPI_ROUTINES_H_ 2 | #define _SPI_ROUTINES_H_ 3 | 4 | #include 5 | 6 | class bSPI { 7 | public: 8 | bSPI() {} 9 | ~bSPI() {} 10 | 11 | void init(); 12 | uint8_t transmit(uint8_t data); 13 | uint8_t receive(); 14 | 15 | void cs_select(); 16 | void cs_unselect(); 17 | }; 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /idf/main/Settings.cpp: -------------------------------------------------------------------------------- 1 | #include "Settings.h" 2 | #include 3 | #include 4 | #include "hardware.h" 5 | 6 | void Settings::initWithParams(void* eepromHost, int eepromHostLength, int port, void* eepromUrl, int eepromUrlLength) 7 | { 8 | _urlData.eepromHost = eepromHost; 9 | _urlData.eepromHostLength = eepromHostLength; 10 | _urlData.port = port; 11 | _urlData.eepromUrl = eepromUrl; 12 | _urlData.eepromUrlLength = eepromUrlLength; 13 | } 14 | 15 | int Settings::getUrl(char* url) 16 | { 17 | bf_eeprom_read_block(url, _urlData.eepromUrl, _urlData.eepromUrlLength); 18 | url[_urlData.eepromUrlLength] = 0; 19 | return _urlData.eepromUrlLength; 20 | } 21 | 22 | int Settings::getHost(char* host) 23 | { 24 | bf_eeprom_read_block(host, _urlData.eepromHost, _urlData.eepromHostLength); 25 | host[_urlData.eepromHostLength] = 0; 26 | return _urlData.eepromHostLength; 27 | } 28 | 29 | int Settings::getPort() 30 | { 31 | return _urlData.port; 32 | } -------------------------------------------------------------------------------- /idf/main/Settings.h: -------------------------------------------------------------------------------- 1 | #ifndef __settings_h__ 2 | #define __settings_h__ 3 | 4 | struct urlData 5 | { 6 | void* eepromHost; 7 | int eepromHostLength; 8 | int port; 9 | void* eepromUrl; 10 | int eepromUrlLength; 11 | }; 12 | 13 | class Settings { 14 | public: 15 | Settings() {}; 16 | ~Settings() {}; 17 | 18 | void initWithParams(void* eepromHost, int eepromHostLength, int port, void* eepromUrl, int eepromUrlLength); 19 | int getUrl(char* url); 20 | int getHost(char* host); 21 | int getPort(); 22 | 23 | private: 24 | urlData _urlData; 25 | }; 26 | 27 | #endif -------------------------------------------------------------------------------- /idf/main/base64.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Base64 encoding/decoding (RFC1341) 3 | * Copyright (c) 2005-2011, Jouni Malinen 4 | * 5 | * This software may be distributed under the terms of the BSD license. 6 | * See README for more details. 7 | */ 8 | #include "base64.hpp" 9 | #include 10 | 11 | static const unsigned char base64_table[65] = 12 | "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; 13 | 14 | /** 15 | * base64_encode - Base64 encode 16 | * @src: Data to be encoded 17 | * @len: Length of the data to be encoded 18 | * @out_len: Pointer to output length variable, or %NULL if not used 19 | * Returns: Allocated buffer of out_len bytes of encoded data, 20 | * or empty string on failure 21 | */ 22 | int base64_len(int len) { 23 | return 4*((len + 2) / 3); 24 | } 25 | 26 | int base64_encode(const uint8_t* src, int len, uint8_t* out) 27 | { 28 | unsigned char *pos; 29 | const unsigned char *end, *in; 30 | 31 | int olen = base64_len(len); 32 | 33 | end = src + len; 34 | in = src; 35 | pos = out; 36 | while (end - in >= 3) { 37 | *pos++ = base64_table[in[0] >> 2]; 38 | *pos++ = base64_table[((in[0] & 0x03) << 4) | (in[1] >> 4)]; 39 | *pos++ = base64_table[((in[1] & 0x0f) << 2) | (in[2] >> 6)]; 40 | *pos++ = base64_table[in[2] & 0x3f]; 41 | in += 3; 42 | } 43 | 44 | if (end - in) { 45 | *pos++ = base64_table[in[0] >> 2]; 46 | if (end - in == 1) { 47 | *pos++ = base64_table[(in[0] & 0x03) << 4]; 48 | *pos++ = '='; 49 | } 50 | else { 51 | *pos++ = base64_table[((in[0] & 0x03) << 4) | 52 | (in[1] >> 4)]; 53 | *pos++ = base64_table[(in[1] & 0x0f) << 2]; 54 | } 55 | *pos++ = '='; 56 | } 57 | 58 | return olen; 59 | } -------------------------------------------------------------------------------- /idf/main/base64.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | int base64_len(int len); 6 | int base64_encode(const uint8_t *src, int len, uint8_t* out); -------------------------------------------------------------------------------- /idf/main/cbmlayout.h: -------------------------------------------------------------------------------- 1 | unsigned char LAYOUT_CBM[] = { 2 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x15, 0x00, 0x00, 0x00, 0x2a, 0x00, 0x00, 3 | 0x00, 0x3f, 0x00, 0x00, 0x00, 0x54, 0x00, 0x00, 0x00, 0x69, 0x00, 0x00, 4 | 0x00, 0x7e, 0x00, 0x00, 0x00, 0x93, 0x00, 0x00, 0x00, 0xa8, 0x00, 0x00, 5 | 0x00, 0xbd, 0x00, 0x00, 0x00, 0xd2, 0x00, 0x00, 0x00, 0xe7, 0x00, 0x00, 6 | 0x00, 0xfc, 0x00, 0x00, 0x00, 0x11, 0x01, 0x00, 0x00, 0x26, 0x01, 0x00, 7 | 0x00, 0x3b, 0x01, 0x00, 0x00, 0x50, 0x01, 0x00, 0x00, 0x65, 0x01, 0x00, 8 | 0x00, 0x78, 0x01, 0x00, 0x00, 0x8b, 0x01, 0x00, 0x00, 0x9e, 0x01, 0x00, 9 | 0x00, 0xb1, 0x01, 0x00, 0x00, 0xc4, 0x01, 0x00, 0x00, 0xd7, 0x01, 0x00, 10 | 0x00, 0xea, 0x01, 0x00, 0x00, 0xfc, 0x01, 0x00, 0x00, 0x0e, 0x02, 0x00, 11 | 0x00, 0x20, 0x02, 0x00, 0x00, 0x32, 0x02, 0x00, 0x00, 0x44, 0x02, 0x00, 12 | 0x00, 0x56, 0x02, 0x00, 0x00, 0x67, 0x02, 0x00, 0x00, 0x78, 0x02, 0x00, 13 | 0x00, 0x89, 0x02, 0x00, 0x00, 0x9a, 0x02, 0x00, 0x00, 0xab, 0x02, 0x00, 14 | 0x00, 0xbc, 0x02, 0x00, 0x00, 0xcd, 0x02, 0x00, 0x00, 0xde, 0x02, 0x00, 15 | 0x00, 0xef, 0x02, 0x00, 0x00, 0x00, 0x03, 0x00 16 | }; 17 | unsigned int LAYOUT_CBM_len = 164; 18 | -------------------------------------------------------------------------------- /idf/main/console.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace Console { 4 | void init(); 5 | void add_command(const char* cmd, const char* help, int(*func)(int,char**)); 6 | } -------------------------------------------------------------------------------- /idf/main/hardware.h: -------------------------------------------------------------------------------- 1 | #ifndef __hardware_h__ 2 | #define __hardware_h__ 3 | 4 | #ifdef ISAVR 5 | #include "hardware_avr.h" 6 | #else 7 | #include "hardware_esp32.h" 8 | #endif 9 | 10 | #include 11 | #include 12 | 13 | #define PACKED __attribute__ ((packed)) 14 | 15 | uint8_t spi_cs(); 16 | void prog_init(); 17 | void init_led(); 18 | void set_led(bool value); 19 | void hDelayMs(int ms); 20 | 21 | uint8_t bf_pgm_read_byte(uint8_t* src); 22 | 23 | void bf_eeprom_write_block(const void* block, void* eeprom, size_t n); 24 | void bf_eeprom_read_block(void* block, const void* eeprom, size_t n); 25 | uint8_t bf_eeprom_read_byte(const uint8_t* addr); 26 | 27 | void spi_init(); 28 | uint8_t spi_transmit(uint8_t data); 29 | void spi_cs_select(); 30 | void spi_cs_unselect(); 31 | 32 | bool isFirmwareFile(char* fname); 33 | 34 | int32_t nvs_get_int(const char* key); 35 | void nvs_set_int(const char* key, int32_t val); 36 | 37 | #endif -------------------------------------------------------------------------------- /idf/main/hardware_esp32.h: -------------------------------------------------------------------------------- 1 | #ifndef __hardware_esp32_h__ 2 | #define __hardware_esp32_h__ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #include "esp-fast-gpio.h" 15 | 16 | #define LOW 0x0 17 | #define HIGH 0x1 18 | #define OUTPUT GPIO_MODE_OUTPUT 19 | #define INPUT_PULLUP GPIO_MODE_INPUT 20 | 21 | #define sscanf_P sscanf 22 | #define sprintf_P sprintf 23 | 24 | #define PSTR(str) str 25 | #define PROGMEM 26 | 27 | void hardware_cmd_init(); 28 | void gpio_init(); 29 | 30 | #define delay_ticks(ticks) vTaskDelay(ticks) 31 | 32 | #ifdef CONFIG_IDF_TARGET_ESP32 33 | #define LED_PIN 2 34 | #define CS_PIN 4 35 | #define MISO_PIN 19 36 | #define MOSI_PIN 23 37 | #define SCK_PIN 18 38 | 39 | #define DATA0 32 40 | #define DATA0_HI 0 41 | #define DATA1 33 42 | #define DATA1_HI 1 43 | #define DATA2 25 44 | #define DATA3 26 45 | #define DATA4 27 46 | #define DATA5 14 47 | #define DATA6 12 48 | #define DATA7 13 49 | 50 | #define DATA_LOW_MASK 0xE007000 51 | #define DATA_HIGH_MASK 0x3 52 | 53 | #define DATADIR 15 54 | 55 | #define ATN_PIN 5 56 | #define EOI_PIN 22 57 | #define DAV_PIN 21 58 | #define NRFD_PIN 17 59 | #define NDAC_PIN 16 60 | 61 | extern uint32_t data_mask_low[256]; 62 | extern uint32_t data_mask_hi[256]; 63 | 64 | #else 65 | // esp32s2 66 | #define LED_PIN 15 67 | #define CS_PIN 4 68 | #define MISO_PIN 37 69 | #define MOSI_PIN 35 70 | #define SCK_PIN 36 71 | 72 | #define DATA0 5 73 | #define DATA1 6 74 | #define DATA2 7 75 | #define DATA3 8 76 | #define DATA4 9 77 | #define DATA5 10 78 | #define DATA6 11 79 | #define DATA7 12 80 | 81 | #define DATADIR 3 82 | 83 | #define ATN_PIN 18 84 | #define EOI_PIN 2 85 | #define DAV_PIN 1 86 | #define NRFD_PIN 21 87 | #define NDAC_PIN 16 88 | 89 | #define DATA_MASK 0b1111111100000 90 | 91 | #endif 92 | 93 | #define lower_eoi() fast_gpio_set_low(EOI_PIN) 94 | #define lower_dav() fast_gpio_set_low(DAV_PIN) 95 | #define lower_nrfd() fast_gpio_set_low(NRFD_PIN) 96 | #define lower_ndac() fast_gpio_set_low(NDAC_PIN) 97 | 98 | #define raise_eoi() fast_gpio_set_high(EOI_PIN) 99 | #define raise_dav() fast_gpio_set_high(DAV_PIN) 100 | #define raise_nrfd() fast_gpio_set_high(NRFD_PIN) 101 | #define raise_ndac() fast_gpio_set_high(NDAC_PIN) 102 | 103 | #define set_eoi_output() fast_gpio_set_output(EOI_PIN) 104 | #define set_dav_output() fast_gpio_set_output(DAV_PIN) 105 | #define set_nrfd_output() fast_gpio_set_output(NRFD_PIN) 106 | #define set_ndac_output() fast_gpio_set_output(NDAC_PIN) 107 | 108 | #define read_atn() fast_gpio_get(ATN_PIN) 109 | #define read_eoi() fast_gpio_get(EOI_PIN) 110 | #define read_dav() fast_gpio_get(DAV_PIN) 111 | #define read_nrfd() fast_gpio_get(NRFD_PIN) 112 | #define read_ndac() fast_gpio_get(NDAC_PIN) 113 | 114 | #define set_atn_input() fast_gpio_set_input(ATN_PIN) 115 | #define set_eoi_input() fast_gpio_set_input(EOI_PIN) 116 | #define set_dav_input() fast_gpio_set_input(DAV_PIN) 117 | #define set_nrfd_input() fast_gpio_set_input(NRFD_PIN) 118 | #define set_ndac_input() fast_gpio_set_input(NDAC_PIN) 119 | 120 | #define set_datadir_output() fast_gpio_set_output(DATADIR) 121 | 122 | #define raise_datadir() fast_gpio_set_high(DATADIR) 123 | #define lower_datadir() fast_gpio_set_low(DATADIR) 124 | 125 | #ifdef CONFIG_IDF_TARGET_ESP32 126 | 127 | #define ieee_read_data_byte(recvByte) ({\ 128 | recvByte += fast_gpio_get(DATA7); recvByte <<= 1;\ 129 | recvByte += fast_gpio_get(DATA6); recvByte <<= 1;\ 130 | recvByte += fast_gpio_get(DATA5); recvByte <<= 1;\ 131 | recvByte += fast_gpio_get(DATA4); recvByte <<= 1;\ 132 | recvByte += fast_gpio_get(DATA3); recvByte <<= 1;\ 133 | recvByte += fast_gpio_get(DATA2); recvByte <<= 1;\ 134 | recvByte += fast_gpio_get_high(DATA1_HI); recvByte <<= 1;\ 135 | recvByte += fast_gpio_get_high(DATA0_HI);\ 136 | }) 137 | 138 | #define ieee_write_data_byte(byte) ({\ 139 | fast_gpio_write_mask(data_mask_low[byte], DATA_LOW_MASK);\ 140 | fast_gpio_write_mask_high(data_mask_hi[byte], DATA_HIGH_MASK);\ 141 | }) 142 | 143 | #define ieee_set_data_output() ({\ 144 | raise_datadir();\ 145 | fast_gpio_set_output_mask(DATA_LOW_MASK);\ 146 | fast_gpio_set_output_mask_high(DATA_HIGH_MASK);\ 147 | }) 148 | 149 | #define ieee_set_data_input() ({\ 150 | fast_gpio_set_input_mask(DATA_LOW_MASK);\ 151 | fast_gpio_set_input_mask_high(DATA_HIGH_MASK);\ 152 | lower_datadir();\ 153 | }) 154 | 155 | #define read_miso() fast_gpio_get(MISO_PIN) 156 | 157 | #else 158 | // esp32s2 159 | #define ieee_read_data_byte(recvByte) recvByte = fast_gpio_read_byte(DATA0) 160 | #define ieee_write_data_byte(byte) fast_gpio_write_byte(byte, DATA0) 161 | 162 | #define ieee_set_data_output() ({\ 163 | raise_datadir();\ 164 | fast_gpio_set_output_mask(DATA_MASK);\ 165 | }) 166 | 167 | #define ieee_set_data_input() ({\ 168 | fast_gpio_set_input_mask(DATA_MASK);\ 169 | lower_datadir();\ 170 | }) 171 | 172 | #define read_miso() fast_gpio_get_high(MISO_PIN-32) 173 | #endif 174 | 175 | #define enable_interrupts() portENABLE_INTERRUPTS() 176 | #define disable_interrupts() portDISABLE_INTERRUPTS() 177 | 178 | #define log_i(format, ...) ESP_LOGI("pd", format, ##__VA_ARGS__) 179 | #define log_d(format, ...) ESP_LOGD("pd", format, ##__VA_ARGS__) 180 | #define log_e(format, ...) ESP_LOGE("pd", format, ##__VA_ARGS__) 181 | 182 | #define log_i_d(format, ...) enable_interrupts(); ESP_LOGI("pd", format, ##__VA_ARGS__); disable_interrupts() 183 | #define log_d_d(format, ...) enable_interrupts(); ESP_LOGD("pd", format, ##__VA_ARGS__); disable_interrupts() 184 | #define log_e_d(format, ...) enable_interrupts(); ESP_LOGE("pd", format, ##__VA_ARGS__); disable_interrupts() 185 | 186 | #define get_time_us() esp_timer_get_time() 187 | 188 | void setup_atn_interrupt(); 189 | void wait_atn_isr(); 190 | void clear_atn(); 191 | 192 | #endif -------------------------------------------------------------------------------- /idf/main/helpers.cpp: -------------------------------------------------------------------------------- 1 | #include "helpers.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | const void *bf_memmem(const void *haystack, size_t haystacklen, const void *needle, size_t needlelen) 8 | { 9 | uint8_t* hh = (uint8_t*)haystack; 10 | uint8_t* nn = (uint8_t*)needle; 11 | 12 | //uint32_t bytesToCheck = haystacklen - needlelen - 1; 13 | int last = haystacklen - needlelen + 1; 14 | for (int i = 0; i < last; i++) 15 | { 16 | if (hh[i] == nn[0]) 17 | { 18 | // compare bytes of haystack and needle 19 | if (memcmp(&hh[i], nn, needlelen) == 0) 20 | { 21 | return &hh[i]; 22 | } 23 | } 24 | } 25 | 26 | return NULL; 27 | } 28 | 29 | void lowerStringInPlace(char* str) 30 | { 31 | char* c = str; 32 | while (*c != 0) 33 | { 34 | *c = tolower(*c); 35 | c++; 36 | } 37 | } 38 | 39 | void upperStringInPlace(char* str) 40 | { 41 | char* c = str; 42 | while (*c != 0) 43 | { 44 | *c = toupper(*c); 45 | c++; 46 | } 47 | } -------------------------------------------------------------------------------- /idf/main/helpers.h: -------------------------------------------------------------------------------- 1 | #ifndef __helpers_h__ 2 | #define __helpers_h__ 3 | 4 | #include 5 | #define PACKED __attribute__ ((packed)) 6 | 7 | const void *bf_memmem( 8 | const void *haystack, size_t haystacklen, 9 | const void *needle, size_t needlelen ); 10 | 11 | void lowerStringInPlace(char* str); 12 | void upperStringInPlace(char* str); 13 | 14 | #endif -------------------------------------------------------------------------------- /idf/main/http.cpp: -------------------------------------------------------------------------------- 1 | #include "http.h" 2 | #include 3 | #include 4 | 5 | namespace HTTP { 6 | 7 | static const char* TAG = "http"; 8 | 9 | #define MIN(a,b) (ab?a:b) 11 | 12 | esp_err_t _http_event_handler(esp_http_client_event_t *evt) 13 | { 14 | static char *output_buffer; // Buffer to store response of http request from event handler 15 | static int output_len; // Stores number of bytes read 16 | switch(evt->event_id) { 17 | case HTTP_EVENT_ON_DATA: 18 | ESP_LOGI(TAG, "HTTP_EVENT_ON_DATA, len=%d", evt->data_len); 19 | // Clean the buffer in case of a new request 20 | if (output_len == 0 && evt->user_data) { 21 | // we are just starting to copy the output data into the use 22 | memset(evt->user_data, 0, 1024); 23 | } 24 | /* 25 | * Check for chunked encoding is added as the URL for chunked encoding used in this example returns binary data. 26 | * However, event handler can also be used in case chunked encoding is used. 27 | */ 28 | if (!esp_http_client_is_chunked_response(evt->client)) { 29 | // If user_data buffer is configured, copy the response into the buffer 30 | int copy_len = 0; 31 | if (evt->user_data) { 32 | // The last byte in evt->user_data is kept for the NULL character in case of out-of-bound access. 33 | copy_len = MIN(evt->data_len, (1024 - output_len)); 34 | if (copy_len) { 35 | memcpy(evt->user_data + output_len, evt->data, copy_len); 36 | } 37 | } else { 38 | int content_len = esp_http_client_get_content_length(evt->client); 39 | if (output_buffer == NULL) { 40 | // We initialize output_buffer with 0 because it is used by strlen() and similar functions therefore should be null terminated. 41 | output_buffer = (char *) calloc(content_len + 1, sizeof(char)); 42 | output_len = 0; 43 | if (output_buffer == NULL) { 44 | ESP_LOGE(TAG, "Failed to allocate memory for output buffer"); 45 | return ESP_FAIL; 46 | } 47 | } 48 | copy_len = MIN(evt->data_len, (content_len - output_len)); 49 | if (copy_len) { 50 | memcpy(output_buffer + output_len, evt->data, copy_len); 51 | } 52 | } 53 | output_len += copy_len; 54 | } 55 | break; 56 | default: 57 | break; 58 | } 59 | return ESP_OK; 60 | } 61 | 62 | int request(const char* url, uint8_t* buffer, int size) { 63 | esp_http_client_config_t config; 64 | memset(&config, 0, sizeof(esp_http_client_config_t)); 65 | config.url = url; 66 | config.event_handler = _http_event_handler; 67 | config.user_data = buffer; 68 | config.disable_auto_redirect = true; 69 | esp_http_client_handle_t client = esp_http_client_init(&config); 70 | 71 | esp_err_t err = esp_http_client_perform(client); 72 | if (err == ESP_OK) { 73 | int content_length = (int)esp_http_client_get_content_length(client); 74 | ESP_LOGI(TAG, "HTTP GET Status = %d, content_length = %d", 75 | esp_http_client_get_status_code(client), 76 | content_length); 77 | return content_length; 78 | } else { 79 | ESP_LOGE(TAG, "HTTP GET request failed: %s", esp_err_to_name(err)); 80 | return -1; 81 | } 82 | } 83 | 84 | } -------------------------------------------------------------------------------- /idf/main/http.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | namespace HTTP { 5 | int request(const char* url, uint8_t* buffer, int size); 6 | } -------------------------------------------------------------------------------- /idf/main/main.cpp.bak: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "hardware.h" 4 | #include "IEEE488.h" 5 | 6 | extern "C" void app_main(void) 7 | { 8 | esp_log_level_set("main", ESP_LOG_INFO); 9 | esp_log_level_set("ieee", ESP_LOG_INFO); 10 | 11 | setupIoConf(); 12 | 13 | ESP_LOGI("main", "hello!"); 14 | bitfixer::IEEE488 ieee; 15 | ieee.init(); 16 | ieee.unlisten(); 17 | 18 | uint8_t dir = 0; 19 | bool success = false; 20 | ieee.get_device_address(&dir, &success); 21 | 22 | ESP_LOGI("main", "dir %d s %d", dir, success); 23 | } 24 | -------------------------------------------------------------------------------- /idf/partitions.csv: -------------------------------------------------------------------------------- 1 | # Name, Type, SubType, Offset, Size, Flags 2 | nvs, data, nvs, 0x9000, 0x5000, 3 | otadata, data, ota, 0xe000, 0x2000, 4 | #app0, app, ota_0, 0x10000, 0x50000, 5 | app0, app, ota_0, 0x60000, 0x1d0000, 6 | app1, app, ota_1, 0x230000,0x1d0000 -------------------------------------------------------------------------------- /idf/scripts/GitHash.cmake: -------------------------------------------------------------------------------- 1 | set(scripts_dir ${CMAKE_SOURCE_DIR}/scripts) 2 | set(git_hash_dir ${CMAKE_SOURCE_DIR}/main) 3 | 4 | function(GetGitHash) 5 | execute_process( 6 | COMMAND python ${scripts_dir}/githash.py ${git_hash_dir}/githash.h 7 | ) 8 | endfunction() -------------------------------------------------------------------------------- /idf/scripts/githash.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import subprocess 3 | 4 | # git rev-parse --short HEAD | tr [:lower:] [:upper:] 5 | 6 | res = subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD']) 7 | res = res.decode('utf-8') 8 | res = res.strip().upper() 9 | 10 | fname = sys.argv[1] 11 | f = open(fname, "w") 12 | print("#pragma once", file=f) 13 | print("const unsigned char _hash[] = \"" + str(res) + "\";", file=f) 14 | f.close() -------------------------------------------------------------------------------- /idf/sdkconfig.defaults: -------------------------------------------------------------------------------- 1 | # This file was generated using idf.py save-defconfig. It can be edited manually. 2 | # Espressif IoT Development Framework (ESP-IDF) 5.4.0 Project Minimal Configuration 3 | # 4 | CONFIG_IDF_TARGET="esp32s2" 5 | CONFIG_APP_REPRODUCIBLE_BUILD=y 6 | CONFIG_APP_RETRIEVE_LEN_ELF_SHA=16 7 | CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y 8 | CONFIG_PARTITION_TABLE_CUSTOM=y 9 | CONFIG_GPIO_CTRL_FUNC_IN_IRAM=y 10 | CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ_240=y 11 | CONFIG_ESP_CONSOLE_USB_CDC=y 12 | CONFIG_ESP_INT_WDT=n 13 | CONFIG_ESP_TASK_WDT_EN=n 14 | CONFIG_ESP_IPC_TASK_STACK_SIZE=4096 15 | CONFIG_ESP_WIFI_STATIC_RX_BUFFER_NUM=2 16 | CONFIG_ESP_WIFI_AMPDU_TX_ENABLED=n 17 | CONFIG_ESP_WIFI_AMPDU_RX_ENABLED=n 18 | CONFIG_ESP_WIFI_NVS_ENABLED=n 19 | CONFIG_ESP_WIFI_IRAM_OPT=n 20 | CONFIG_ESP_WIFI_RX_IRAM_OPT=n 21 | CONFIG_ESP_WIFI_GMAC_SUPPORT=n 22 | CONFIG_ESP_WIFI_SOFTAP_SUPPORT=n 23 | CONFIG_ESP_WIFI_ENTERPRISE_SUPPORT=n 24 | CONFIG_FREERTOS_HZ=1000 25 | CONFIG_LOG_MAXIMUM_LEVEL_VERBOSE=y 26 | CONFIG_LWIP_TCP_SND_BUF_DEFAULT=5744 27 | CONFIG_LWIP_TCP_WND_DEFAULT=5744 28 | -------------------------------------------------------------------------------- /idf/sdkconfig.defaults.esp32: -------------------------------------------------------------------------------- 1 | CONFIG_IDF_TARGET="esp32" -------------------------------------------------------------------------------- /idf/sdkconfig.defaults.esp32s2: -------------------------------------------------------------------------------- 1 | CONFIG_IDF_TARGET="esp32s2" 2 | CONFIG_ESP_CONSOLE_USB_CDC=y -------------------------------------------------------------------------------- /legacy/Makefile: -------------------------------------------------------------------------------- 1 | # Name: Makefile 2 | # Author: 3 | # Copyright: 4 | # License: 5 | 6 | DEVICE = atmega1284p 7 | CLOCK = 8000000 8 | PROGRAMMER = -c linuxspi -P /dev/spidev0.0 9 | SRCDIR = src 10 | BIN = bin 11 | AVRDIR = $(SRCDIR)/avr 12 | BLDIR = $(AVRDIR)/bootloader 13 | 14 | OBJECTS = \ 15 | $(SRCDIR)/avr/avr_main.o\ 16 | $(SRCDIR)/petdisk.o\ 17 | $(SRCDIR)/Serial.o\ 18 | $(SRCDIR)/EspHttp.o\ 19 | $(SRCDIR)/SD_routines.o\ 20 | $(SRCDIR)/SPI_routines.o\ 21 | $(SRCDIR)/FAT32.o\ 22 | $(SRCDIR)/IEEE488.o\ 23 | $(SRCDIR)/NetworkDataSource.o\ 24 | $(SRCDIR)/D64DataSource.o\ 25 | $(SRCDIR)/Settings.o\ 26 | $(SRCDIR)/helpers.o\ 27 | $(SRCDIR)/avr/EspConn.o\ 28 | $(SRCDIR)/avr/hardware_avr.o 29 | 30 | BOOTLOADER_OBJECTS = $(BLDIR)/bootloader.o\ 31 | $(BLDIR)/SPI_routines.o\ 32 | $(BLDIR)/SD_routines.o\ 33 | $(BLDIR)/FAT32_tiny.o 34 | 35 | INCLUDE = -I./src/avr 36 | 37 | FUSES = -U lfuse:w:0xc2:m -U hfuse:w:0xda:m -U efuse:w:0xff:m -U lock:w:0xEF:m 38 | 39 | # For computing fuse byte values for other devices and options see 40 | # the fuse bit calculator at http://www.engbedded.com/fusecalc/ 41 | # also http://eleccelerator.com/fusecalc/fusecalc.php 42 | 43 | # Tune the lines below only if you know what you are doing: 44 | 45 | AVRDUDE = avrdude $(PROGRAMMER) -p $(DEVICE) -V 46 | COMPILE = avr-g++ -Wall -Os -DISAVR=1 -DF_CPU=$(CLOCK) -mmcu=$(DEVICE) -std=gnu99 $(INCLUDE) 47 | COMPILECPP = avr-g++ -Wall -Os -DISAVR=1 -DF_CPU=$(CLOCK) -mmcu=$(DEVICE) -std=c++11 $(INCLUDE) 48 | 49 | BOOTLOADER_ADDR_324_H = 0x7000 50 | BOOTLOADER_ADDR_644_H = 0xF000 51 | BOOTLOADER_ADDR_1284_H = 0x1F000 52 | BOOTLOADER_ADDR_324_D = 28672 53 | BOOTLOADER_ADDR_644_D = 61440 54 | BOOTLOADER_ADDR_1284_D = 126976 55 | 56 | PI_ADDRESS = raspberrypi.local 57 | 58 | # pin definitions 59 | 60 | RESET_PIN = 6 61 | 62 | # symbolic targets: 63 | all: petdisk.hex 64 | 65 | .c.o: 66 | $(COMPILE) -c $< -o $@ 67 | 68 | .cpp.o: 69 | $(COMPILECPP) -c $< -o $@ 70 | 71 | .S.o: 72 | $(COMPILE) -x assembler-with-cpp -c $< -o $@ 73 | # "-x assembler-with-cpp" should not be necessary since this is the default 74 | # file type for the .S (with capital S) extension. However, upper case 75 | # characters are not always preserved on Windows. To ensure WinAVR 76 | # compatibility define the file type manually. 77 | 78 | .c.s: 79 | $(COMPILE) -S $< -o $@ 80 | 81 | %.flash: 82 | $(AVRDUDE) -U flash:w:$*.hex 83 | 84 | %.flashbin: 85 | $(AVRDUDE) -U flash:w:$*.bin -V 86 | 87 | fuse: 88 | $(AVRDUDE) -b115200 $(FUSES) 89 | 90 | %.program: %.hex 91 | make progenable 92 | sudo make $*.install 93 | make progdisable 94 | 95 | %.programbin: 96 | make progenable 97 | sudo make $*.installbin 98 | make progdisable 99 | 100 | %.install: %.hex 101 | make fuse 102 | make $*.flash 103 | 104 | %.installbin: 105 | make fuse 106 | make $*.flashbin 107 | 108 | progenable: 109 | gpio mode 12 alt0 110 | gpio mode 13 alt0 111 | gpio mode 14 alt0 112 | gpio mode $(RESET_PIN) in 113 | 114 | progdisable: 115 | gpio mode 12 in 116 | gpio mode 13 in 117 | gpio mode 14 in 118 | gpio mode $(RESET_PIN) out 119 | gpio write $(RESET_PIN) 0 120 | gpio write $(RESET_PIN) 1 121 | 122 | clean: 123 | rm -f *.hex *.elf *.o *.bin 124 | rm -f $(SRCDIR)/*.o 125 | rm -f $(AVRDIR)/*.o 126 | rm -f $(BLDIR)/*.o 127 | rm -f $(BIN)/* 128 | 129 | $(SRCDIR)/githash.h: 130 | echo \#include \"hardware.h\" > $@ 131 | echo const unsigned char _hash[] PROGMEM = \"$(shell git rev-parse --short HEAD | tr [:lower:] [:upper:])\"\; >> $@ 132 | 133 | # file targets: 134 | %.elf: bindir $(SRCDIR)/githash.h $(OBJECTS) 135 | $(COMPILECPP) -o $*.elf $(OBJECTS) 136 | rm -f $(SRCDIR)/githash.h 137 | 138 | %.hex: bindir %.elf 139 | rm -f $*.heximage 140 | avr-objcopy -j .text -j .data -O ihex $*.elf $*.hex 141 | avr-size --format=avr --mcu=$(DEVICE) $*.elf 142 | # If you have an EEPROM section, you must also create a hex file for the 143 | # EEPROM and add it to the "flassh" target. 144 | 145 | %.bin: bindir %.elf 146 | rm -f $*.bin 147 | avr-objcopy -j .text -j .data -O binary $*.elf $*.bin 148 | avr-size --format=avr --mcu=$(DEVICE) $*.elf 149 | 150 | # Targets for code debugging and analysis: 151 | disasm: %.elf 152 | avr-objdump -d $*.elf 153 | 154 | $(BIN)/bootloader.elf: bindir $(BOOTLOADER_OBJECTS) 155 | $(COMPILECPP) -Ttext=$(BOOTLOADER_ADDR_1284_H) -o $(BIN)/bootloader.elf $(BOOTLOADER_OBJECTS) 156 | 157 | # pad the end of the main program with zeros, leaving enough room for the bootloader 158 | $(BIN)/petdisk_and_bootloader.bin: bindir $(BIN)/petdisk.bin $(BIN)/bootloader.bin $(BIN)/filesize 159 | dd if=/dev/zero bs=1 count=$(shell expr $(BOOTLOADER_ADDR_1284_D) - $(shell $(BIN)/filesize $(BIN)/petdisk.bin)) >> $(BIN)/petdisk.bin 160 | cat $(BIN)/petdisk.bin $(BIN)/bootloader.bin > $(BIN)/petdisk_and_bootloader.bin 161 | 162 | $(BIN)/filesize: $(SRCDIR)/tools/filesize.cpp 163 | g++ $(SRCDIR)/tools/filesize.cpp -o $(BIN)/filesize 164 | 165 | bindir: 166 | mkdir -p bin 167 | 168 | reset: 169 | gpio write $(RESET_PIN) 0 170 | gpio write $(RESET_PIN) 1 171 | 172 | transfer: bin/petdisk.bin 173 | scp bin/petdisk.bin pi@${PI_ADDRESS}:~/petdisk_v2/petdisk-max/bin 174 | 175 | -------------------------------------------------------------------------------- /legacy/PETDISK.CFG: -------------------------------------------------------------------------------- 1 | 8,SD0 2 | 10,bitfixer.com/pd/petdisk.php 3 | ssid,networkname 4 | password,networkpassword 5 | -------------------------------------------------------------------------------- /legacy/githash.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | print("getting git hash") 4 | os.system("rm -f src/githash.h") 5 | os.system("make src/githash.h") -------------------------------------------------------------------------------- /legacy/partitions.csv: -------------------------------------------------------------------------------- 1 | # Name, Type, SubType, Offset, Size, Flags 2 | nvs, data, nvs, 0x9000, 0x5000, 3 | otadata, data, ota, 0xe000, 0x2000, 4 | app0, app, ota_0, 0x10000, 0x50000, 5 | app1, app, ota_1, 0x60000, 0x230000, 6 | spiffs, data, spiffs, 0x290000,0x170000, -------------------------------------------------------------------------------- /legacy/platformio.ini: -------------------------------------------------------------------------------- 1 | ; PlatformIO Project Configuration File 2 | ; 3 | ; Build options: build flags, source filter 4 | ; Upload options: custom upload port, speed and extra flags 5 | ; Library options: dependencies, extra library storages 6 | ; Advanced options: extra scripting 7 | ; 8 | ; Please visit documentation for the other options and examples 9 | ; https://docs.platformio.org/page/projectconf.html 10 | 11 | [env] 12 | platform = espressif32@4.2 13 | board = esp32dev 14 | 15 | [env:petdisk-max] 16 | framework = arduino 17 | 18 | monitor_speed = 115200 19 | src_filter = ${env.src_filter} - - + 20 | build_flags=-Isrc/esp32 21 | extra_scripts = pre:githash.py, reset.py 22 | 23 | [env:sd_loader] 24 | framework = arduino, espidf 25 | 26 | platform_packages = 27 | framework-arduinoespressif32@^3.20011.230801 28 | 29 | monitor_speed = 115200 30 | ; monitor_port = /dev/cu.SLAB_USBtoUART 31 | build_flags=-Isrc/esp32 32 | board_build.partitions = partitions.csv 33 | extra_scripts = reset.py -------------------------------------------------------------------------------- /legacy/reset.py: -------------------------------------------------------------------------------- 1 | Import("env") 2 | import os 3 | from platformio.builder.tools.pioupload import AutodetectUploadPort 4 | 5 | platform = env.PioPlatform() 6 | 7 | AutodetectUploadPort(env) 8 | upload_port = env.subst('$UPLOAD_PORT') 9 | 10 | reset_flags = '--before default_reset --after hard_reset' 11 | 12 | esptool = os.path.join(platform.get_package_dir("tool-esptoolpy"), "esptool.py") 13 | esptool_cmd = f'$PYTHONEXE "{esptool}" --port {upload_port} {reset_flags} --no-stub run' 14 | 15 | # Multiple actions 16 | env.AddCustomTarget( 17 | name="reset", 18 | dependencies=None, 19 | actions=[ 20 | esptool_cmd, 21 | "pio device monitor" 22 | ], 23 | title="Reset ESP32", 24 | description="Resets the ESP32 board" 25 | ) -------------------------------------------------------------------------------- /legacy/src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # This file was automatically generated for projects 2 | # without default 'CMakeLists.txt' file. 3 | 4 | FILE(GLOB app_sources 5 | ${CMAKE_SOURCE_DIR}/src/esp32/hardware_esp32.* 6 | ${CMAKE_SOURCE_DIR}/src/sd_loader/*.* 7 | ${CMAKE_SOURCE_DIR}/src/hardware.h 8 | ${CMAKE_SOURCE_DIR}/src/helpers.* 9 | ${CMAKE_SOURCE_DIR}/src/FAT32.* 10 | ${CMAKE_SOURCE_DIR}/src/SD_routines.* 11 | ${CMAKE_SOURCE_DIR}/src/SPI_routines.* 12 | ${CMAKE_SOURCE_DIR}/src/Serial.*) 13 | idf_component_register(SRCS ${app_sources}) 14 | -------------------------------------------------------------------------------- /legacy/src/ConsoleLogger.cpp: -------------------------------------------------------------------------------- 1 | #include "ConsoleLogger.h" 2 | 3 | void ConsoleLogger::init() 4 | { 5 | } 6 | 7 | void ConsoleLogger::log(const char* str) 8 | { 9 | ::printf(str); 10 | } 11 | 12 | void ConsoleLogger::log(unsigned char* data, int length) 13 | { 14 | for (int i = 0; i < length; i++) 15 | { 16 | ::printf("%c", data[i]); 17 | } 18 | } 19 | 20 | void ConsoleLogger::logF(const char* str) 21 | { 22 | 23 | } -------------------------------------------------------------------------------- /legacy/src/ConsoleLogger.h: -------------------------------------------------------------------------------- 1 | #ifndef __console_logger_h__ 2 | #define __console_logger_h__ 3 | 4 | #include "Logger.h" 5 | 6 | #include 7 | #include 8 | 9 | class ConsoleLogger : public Logger { 10 | public: 11 | ConsoleLogger() {}; 12 | ~ConsoleLogger() {}; 13 | 14 | void init(); 15 | void log(const char* str); 16 | void log(unsigned char* data, int length); 17 | void logF(const char* str); 18 | }; 19 | 20 | #endif -------------------------------------------------------------------------------- /legacy/src/D64DataSource.h: -------------------------------------------------------------------------------- 1 | #ifndef __d64_datasource_h__ 2 | #define __d64_datasource_h__ 3 | 4 | #include 5 | #include 6 | #include "DataSource.h" 7 | #include "Logger.h" 8 | 9 | // need to mount a file as a d64 filesystem 10 | // the file will be served from another datasource 11 | // needs to support searching for a file and seeking within the file 12 | 13 | #define BLOCK_SIZE 256 14 | #define BAM_SIZE 4*35 15 | #define DISK_TRACKS 40 16 | #define MAX_TRACKS 35 17 | 18 | #define DEL_TYPE 0x80 19 | #define SEQ_TYPE 0x81 20 | #define PRG_TYPE 0x82 21 | #define USR_TYPE 0x83 22 | #define REL_TYPE 0x84 23 | 24 | typedef struct CBMHeader 25 | { 26 | uint8_t nextBlock[2]; 27 | uint8_t dosVersion; 28 | uint8_t unused1; 29 | uint8_t bam[BAM_SIZE]; 30 | uint8_t diskName[16]; 31 | uint8_t id[2]; 32 | uint8_t unused2; // Usually $A0 33 | uint8_t dosType[2]; 34 | uint8_t unused3[4]; // Usually $A0 35 | uint8_t track40Extended[55]; // Usually $00, except for 40 track format 36 | } CBMHeader; 37 | 38 | typedef struct 39 | { 40 | uint8_t nextBlock[2]; // Track and block of next directory 41 | // block. When the first byte is 00 42 | // that is the last block. 43 | 44 | uint8_t fileType; 45 | // 0x80 = DELeted 46 | // 0x81 = SEQuential 47 | // 0x82 = PROGram 48 | // 0x83 = USER 49 | // 0x84 = RELative 50 | 51 | uint8_t dataBlock[2]; // Track and block of first data block 52 | uint8_t fileName[16]; // Filename padded with spaces 53 | uint8_t sideSector[2]; // Relative only track and block first side 54 | // sector. 55 | 56 | uint8_t recordSize; // Relative file only. Record Size. 57 | uint8_t unused[6]; // Unused bytes 58 | 59 | uint8_t fileSize[2]; // Number of blocks in file. Low Byte, High Byte. 60 | } CBMFile_Entry; 61 | 62 | typedef struct 63 | { 64 | CBMFile_Entry *file; 65 | int files; 66 | } CBMDirectory; 67 | 68 | typedef struct 69 | { 70 | CBMHeader header; 71 | CBMDirectory directory; 72 | } CBMDisk; 73 | 74 | // ERROR CODES 75 | #define D64_FILE_ERROR -1 76 | #define D64_OUT_OF_MEMORY -2 77 | #define D64_OUT_OF_RANGE -3 78 | #define D64_FILE_NOT_FOUND -4 79 | #define D64_ERROR -5 80 | #define D64_FILE_NOT_OPEN -6 81 | #define D64_FILE_EXISTS -7 82 | 83 | class D64DataSource : public DataSource 84 | { 85 | public: 86 | D64DataSource() {} 87 | ~D64DataSource() {} 88 | 89 | bool init() 90 | { 91 | return true; 92 | } 93 | 94 | bool initWithDataSource(DataSource* dataSource, const char* fileName, Logger* logger); 95 | 96 | void openFileForWriting(uint8_t* fileName); 97 | bool openFileForReading(uint8_t* fileName); 98 | uint32_t seek(uint16_t position); 99 | 100 | bool openDirectory(const char* dirName); 101 | uint16_t getNextFileBlock(); 102 | bool isLastBlock(); 103 | bool getNextDirectoryEntry(); 104 | bool isInitialized(); 105 | 106 | void writeBufferToFile(uint16_t numBytes); 107 | void closeFile(); 108 | void openCurrentDirectory(); 109 | uint8_t* getFilename(); 110 | uint8_t* getBuffer(); 111 | uint16_t writeBufferSize(); 112 | uint16_t readBufferSize(); 113 | void processCommandString(int* address); 114 | 115 | DataSource* getFileDataSource(); 116 | 117 | private: 118 | DataSource* _fileDataSource; 119 | CBMFile_Entry* _currentFileEntry; 120 | uint8_t _fileName[21]; 121 | uint8_t* _cbmBuffer; 122 | uint32_t* _cbmTrackLayout; 123 | uint8_t _dirTrackBlock[2]; 124 | uint8_t _fileTrackBlock[2]; 125 | uint8_t _fileFirstTrackBlock[2]; 126 | uint8_t _dirIndexInBuffer; 127 | uint8_t _cbmBAM[BAM_SIZE]; 128 | uint16_t _blocksInFile; 129 | bool _directBlockAccess; 130 | Logger* _logger; 131 | 132 | void prepareNextBlockForWriting(); 133 | 134 | void cbmMount(); 135 | void cbmPrintHeader(CBMDisk* disk); 136 | CBMHeader* cbmLoadHeader(); 137 | void cbmSaveHeader(); 138 | uint32_t cbmBlockLocation(uint8_t* tb); 139 | uint8_t* cbmReadBlock(uint8_t* tb); 140 | void cbmWriteBlock(uint8_t* tb); 141 | uint8_t* cbmEmptyBlockChain(CBMDisk* disk); 142 | void cbmPrintFileEntry(CBMFile_Entry* entry); 143 | CBMFile_Entry* cbmGetNextFileEntry(); 144 | CBMFile_Entry* cbmSearch(uint8_t* searchNameA, uint8_t fileType); 145 | uint8_t* cbmD64StringCString(uint8_t* dest, const uint8_t* source); 146 | uint8_t* cbmCopyString(uint8_t* dest, const uint8_t* source); 147 | bool cbmFindEmptyBlock(uint8_t* tb); 148 | uint8_t cbmSectorsPerTrack(uint8_t track); 149 | bool cbmIsBlockFree(uint8_t* tb); 150 | int cbmBAM(uint8_t *tb, char s); 151 | void cbmCreateFileEntry(uint8_t* fileName, uint8_t fileType, uint16_t blocksInFile); 152 | bool findEmptyDirectoryBlock(uint8_t* tb); 153 | bool createNewDirectoryBlock(uint8_t* tb); 154 | 155 | }; 156 | 157 | #endif -------------------------------------------------------------------------------- /legacy/src/DataSource.h: -------------------------------------------------------------------------------- 1 | #ifndef __datasource_h__ 2 | #define __datasource_h__ 3 | 4 | #include 5 | 6 | class DataSource 7 | { 8 | public: 9 | DataSource() {} 10 | ~DataSource() {} 11 | 12 | virtual bool init() = 0; 13 | virtual void openFileForWriting(uint8_t* fileName) = 0; 14 | virtual bool openFileForReading(uint8_t* fileName) = 0; 15 | virtual bool openDirectory(const char* dirName) = 0; 16 | virtual uint16_t getNextFileBlock() = 0; 17 | virtual bool isLastBlock() = 0; 18 | virtual bool getNextDirectoryEntry() = 0; 19 | virtual bool isInitialized() = 0; 20 | virtual void writeBufferToFile(uint16_t numBytes) = 0; 21 | virtual void updateBlock() {} 22 | virtual void closeFile() = 0; 23 | virtual void openCurrentDirectory() = 0; 24 | virtual uint32_t seek(uint32_t pos) { return 0; } 25 | virtual bool isHidden() { return false; } 26 | virtual bool isVolumeId() { return false; } 27 | virtual bool isDirectory() { return false; } 28 | virtual uint8_t* getFilename() = 0; 29 | virtual uint8_t* getBuffer() = 0; 30 | virtual uint16_t writeBufferSize() = 0; 31 | virtual uint16_t readBufferSize() { return 512; } 32 | virtual uint16_t requestReadBufferSize(uint16_t requestedReadBufferSize) { 33 | // default to not changing read buffer size 34 | return 512; 35 | } 36 | virtual uint16_t requestWriteBufferSize(uint16_t requestedWriteBufferSize) { 37 | return 512; 38 | } 39 | 40 | virtual void processCommandString(int* address) {} // default no action 41 | virtual bool needRealTime() { return false; } 42 | virtual void setDateTime(int year, int month, int day, int hour, int minute, int second) {} 43 | }; 44 | 45 | #endif -------------------------------------------------------------------------------- /legacy/src/EspConn.h: -------------------------------------------------------------------------------- 1 | #ifndef __esp_conn_h__ 2 | #define __esp_conn_h__ 3 | 4 | #include 5 | #include "SerialLogger.h" 6 | #include "Serial.h" 7 | 8 | namespace bitfixer 9 | { 10 | 11 | typedef enum eProtMode {TCP_MODE, UDP_MODE, SSL_MODE} tProtMode; 12 | typedef enum 13 | { 14 | TAG_OK, 15 | TAG_ERROR, 16 | TAG_FAIL, 17 | TAG_SENDOK, 18 | TAG_CONNECT 19 | } TagsEnum; 20 | 21 | class EspConn { 22 | public: 23 | EspConn() 24 | : _serialBuffer(NULL) 25 | , _serialBufferSize(NULL) 26 | , _serial(NULL) 27 | , _logSerial(NULL) 28 | { 29 | 30 | } 31 | 32 | EspConn(uint8_t* buffer, uint16_t* bufferSize, Serial* serial, Logger* logSerial) : 33 | _serialBuffer(buffer), 34 | _serialBufferSize(bufferSize), 35 | _serial(serial), 36 | _logSerial(logSerial) 37 | { 38 | 39 | } 40 | 41 | bool initWithParams(uint8_t* buffer, uint16_t* bufferSize, Serial* serial, Logger* logSerial); 42 | bool init(); 43 | bool device_present(); 44 | bool attempt_baud_rate_setting(); 45 | 46 | void scanNetworks(); 47 | 48 | void setDns(); 49 | bool connect(const char* ssid, const char* passphrase); 50 | bool startClient(const char* host, uint16_t port, uint8_t sock, uint8_t protMode); 51 | void stopClient(uint8_t sock); 52 | 53 | void sendData(uint8_t sock, unsigned char* data, int len); 54 | int readUntil(const char* tag, bool findTags, bool end, int timeout); 55 | bool sendCmd(const char* cmd, int timeout=30000); 56 | void reset(); 57 | 58 | private: 59 | 60 | void readBytesUntilSize(uint16_t size); 61 | void copyEscapedString(char* dest, const char* src); 62 | 63 | uint8_t* _serialBuffer; 64 | uint16_t* _serialBufferSize; 65 | Serial* _serial; 66 | Logger* _logSerial; 67 | }; 68 | 69 | } 70 | 71 | #endif -------------------------------------------------------------------------------- /legacy/src/EspHttp.cpp: -------------------------------------------------------------------------------- 1 | #include "EspHttp.h" 2 | #include 3 | #include 4 | #include 5 | #include "hardware.h" 6 | #include "helpers.h" 7 | 8 | namespace bitfixer { 9 | 10 | void EspHttp::initWithParams(EspConn* espConn, Logger* log) 11 | { 12 | _espConn = espConn; 13 | _log = log; 14 | } 15 | 16 | bool EspHttp::postBlock(char* host, int port, char* url, char* params, uint8_t* buffer, uint16_t* bufferSize, int numBytes) 17 | { 18 | // prepare url 19 | urlInfo* info = (urlInfo*)buffer; 20 | sprintf_P(info->urlstring, PSTR("PUT %s%s HTTP/1.0\r\nHost: %s\r\nContent-Length: %d\r\n\r\n"), url, params, host, numBytes); 21 | 22 | // move url string to immediately behind payload data 23 | int url_strlen = strlen(info->urlstring); 24 | char* startpos = info->blockData - url_strlen; 25 | memmove(startpos, info->urlstring, url_strlen); 26 | 27 | int full_data_length = url_strlen + numBytes; 28 | 29 | if (!_espConn->startClient(host, port, 0, TCP_MODE)) 30 | { 31 | // error 32 | return false; 33 | } 34 | _espConn->sendData(0, (unsigned char*)startpos, full_data_length); 35 | return true; 36 | } 37 | 38 | uint8_t* EspHttp::makeRequest(const char* host, int port, const char* url, const char* params, uint8_t* buffer, uint16_t* bufferSize, int* size) 39 | { 40 | urlInfo* info = (urlInfo*)buffer; 41 | char* data = info->urlstring; 42 | 43 | sprintf_P(data, PSTR("GET %s%s HTTP/1.0\r\nHost: %s\r\n\r\n"), url, params, host); 44 | if (!_espConn->startClient(host, port, 0, TCP_MODE)) 45 | { 46 | return NULL; 47 | } 48 | _espConn->sendData(0, (unsigned char*)data, strlen(data)); 49 | int bufSize = *bufferSize; 50 | 51 | // parse data from serial buffer 52 | // find beginning of HTTP message 53 | uint8_t* httpStart = (uint8_t*)bf_memmem(buffer, bufSize, "HTTP", 4); 54 | if (httpStart == 0) 55 | { 56 | *size = 0; 57 | return 0; 58 | } 59 | 60 | int httpSize = bufSize - (httpStart - buffer); 61 | 62 | // find blank newline to signify beginning of payload data 63 | uint8_t* datastart = (uint8_t*)bf_memmem(httpStart, httpSize, "\r\n\r\n", 4); 64 | 65 | if (datastart == 0) 66 | { 67 | *size = -1; 68 | return 0; 69 | } 70 | 71 | datastart += 4; 72 | *size = bufSize - (datastart - buffer); 73 | return datastart; 74 | } 75 | 76 | uint32_t EspHttp::getSize(const char* host, int port, const char* url, uint8_t* buffer, uint16_t* bufferSize) 77 | { 78 | uint8_t* datastart; 79 | uint32_t fileSize; 80 | int size; 81 | datastart = makeRequest(host, port, url, "&l=1", buffer, bufferSize, &size); 82 | if (datastart == NULL) 83 | { 84 | return 0; 85 | } 86 | 87 | sscanf((const char*)datastart, "%" SCNu32 "\r\n", &fileSize); 88 | _log->printf("got size %ld\r\n", fileSize); 89 | return fileSize; 90 | } 91 | 92 | uint8_t* EspHttp::getRange(const char* host, int port, const char* url, uint32_t start, uint32_t end, uint8_t* buffer, uint16_t* bufferSize, int* size) 93 | { 94 | char params[25]; 95 | sprintf_P(params, PSTR("&s=%" PRIu32 "&e=%" PRIu32), start, end); 96 | return makeRequest(host, port, url, (const char*)params, buffer, bufferSize, size); 97 | } 98 | 99 | } -------------------------------------------------------------------------------- /legacy/src/EspHttp.h: -------------------------------------------------------------------------------- 1 | #ifndef __esp_http_h__ 2 | #define __esp_http_h__ 3 | 4 | #include "EspConn.h" 5 | #include 6 | #include "SerialLogger.h" 7 | 8 | namespace bitfixer 9 | { 10 | 11 | struct __attribute__ ((packed)) urlInfo { 12 | char host[64]; 13 | char url[64]; 14 | char params[64]; 15 | char urlstring[256]; 16 | char blockData[512]; 17 | char fileName[64]; 18 | }; 19 | 20 | class EspHttp 21 | { 22 | public: 23 | EspHttp() 24 | : _espConn(NULL) 25 | , _log(NULL) 26 | {} 27 | 28 | EspHttp(EspConn* espConn, Logger* log) 29 | : _espConn(espConn) 30 | , _log(log) 31 | {} 32 | 33 | ~EspHttp() {} 34 | 35 | void initWithParams(EspConn* espConn, Logger* log); 36 | bool postBlock(char* host, int port, char* url, char* params, uint8_t* buffer, uint16_t* bufferSize, int numBytes); 37 | uint8_t* makeRequest(const char* host, int port, const char* url, const char* params, uint8_t* buffer, uint16_t* bufferSize, int* size); 38 | uint32_t getSize(const char* host, int port, const char* url, uint8_t* buffer, uint16_t* bufferSize); 39 | uint8_t* getRange(const char* host, int port, const char* url, uint32_t start, uint32_t end, uint8_t* buffer, uint16_t* bufferSize, int* size); 40 | 41 | int getSizeE(const char* host, const char* url, uint8_t* buffer, uint16_t* bufferSize); 42 | 43 | private: 44 | EspConn* _espConn; 45 | Logger* _log; 46 | }; 47 | 48 | } 49 | 50 | #endif -------------------------------------------------------------------------------- /legacy/src/EspLogger.h: -------------------------------------------------------------------------------- 1 | #ifndef __esp_logger_h__ 2 | #define __esp_logger_h__ 3 | 4 | #include "EspConn.h" 5 | 6 | class EspLogger { 7 | public: 8 | EspLogger(EspConn* espConn) 9 | : _espConn(espConn) { 10 | 11 | } 12 | 13 | void init() 14 | { 15 | _espConn->startClient("192.168.0.110", 8080, 4, UDP_MODE); 16 | } 17 | 18 | void log(const char* str) 19 | { 20 | _espConn->sendData(4, (unsigned char*)str, strlen(str)); 21 | } 22 | 23 | void log(unsigned char* data, int length) 24 | { 25 | _espConn->sendData(4, data, length); 26 | } 27 | 28 | private: 29 | EspConn* _espConn; 30 | }; 31 | 32 | #endif -------------------------------------------------------------------------------- /legacy/src/FAT32.h: -------------------------------------------------------------------------------- 1 | /* 2 | FAT32.h 3 | FAT32 filesystem Routines in the PETdisk storage device 4 | Copyright (C) 2011 Michael Hill 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | 19 | Contact the author at bitfixer@bitfixer.com 20 | http://bitfixer.com 21 | */ 22 | 23 | #ifndef _FAT32_H_ 24 | #define _FAT32_H_ 25 | 26 | #include "SD_routines.h" 27 | #include "SerialLogger.h" 28 | #include "DataSource.h" 29 | #include "helpers.h" 30 | #include 31 | 32 | //Structure to access Directory Entry in the FAT 33 | struct PACKED dir_Structure{ 34 | uint8_t name[11]; //0 35 | uint8_t attrib; //11 //file attributes 36 | uint8_t NTreserved; //12 //always 0 37 | uint8_t timeTenth; //13 //tenths of seconds, set to 0 here 38 | uint16_t createTime; //14 //time file was created 39 | uint16_t createDate; //16 //date file was created 40 | uint16_t lastAccessDate;//18 41 | uint16_t firstClusterHI;//20 //higher word of the first cluster number 42 | uint16_t writeTime; //22 //time of last write 43 | uint16_t writeDate; //24 //date of last write 44 | uint16_t firstClusterLO;//26 //lower word of the first cluster number 45 | uint32_t fileSize; //28 //size of file in bytes 46 | //32 47 | }; 48 | 49 | struct PACKED dir_Longentry_Structure{ 50 | uint8_t LDIR_Ord; 51 | uint16_t LDIR_Name1[5]; 52 | uint8_t LDIR_Attr; 53 | uint8_t LDIR_Type; 54 | uint8_t LDIR_Chksum; 55 | uint16_t LDIR_Name2[6]; 56 | uint16_t LDIR_FstClusLO; 57 | uint16_t LDIR_Name3[2]; 58 | }; 59 | 60 | // structure for file read information 61 | typedef struct PACKED _file_stat{ 62 | uint32_t currentCluster; 63 | uint32_t fileSize; 64 | uint32_t currentSector; 65 | uint32_t byteCounter; 66 | int sectorIndex; 67 | } file_stat; 68 | 69 | typedef struct PACKED _file_position { 70 | uint8_t isLongFilename; 71 | uint8_t *fileName; 72 | uint32_t startCluster; 73 | uint32_t cluster; 74 | uint32_t dirStartCluster; 75 | uint8_t sectorIndex; 76 | uint32_t sector; 77 | uint32_t fileSize; 78 | uint32_t byteCounter; 79 | uint16_t byte; 80 | uint8_t shortFilename[11]; 81 | } file_position; 82 | 83 | #define MAX_FILENAME 256 84 | 85 | namespace bitfixer { 86 | 87 | class FAT32 : public DataSource 88 | { 89 | public: 90 | FAT32() 91 | : _sd(NULL) 92 | , _FatBuffer(NULL) 93 | , _longEntryString(NULL) 94 | , _logger(NULL) 95 | , _currentDirectoryEntry(0) 96 | , _initialized(false) 97 | , _rootCluster(0) 98 | , _timeValue(0) 99 | , _dateValue(0) 100 | { 101 | 102 | } 103 | 104 | FAT32(SD* sd, uint8_t* fatbuffer, uint8_t* longEntryBuffer, SerialLogger* logger) 105 | : _sd(sd) 106 | , _FatBuffer(fatbuffer) 107 | , _longEntryString(longEntryBuffer) 108 | , _logger(logger) 109 | , _currentDirectoryEntry(0) 110 | , _initialized(false) 111 | , _rootCluster(0) 112 | , _timeValue(0) 113 | , _dateValue(0) 114 | { 115 | 116 | } 117 | 118 | ~FAT32() {} 119 | 120 | bool initWithParams(SD* sd, uint8_t* fatbuffer, uint8_t* longEntryBuffer, SerialLogger* logger); 121 | bool init(); 122 | bool isInitialized(); 123 | uint8_t* getLongEntryString(); 124 | 125 | void openDirectory(uint32_t firstCluster); 126 | bool getNextDirectoryEntry(); 127 | bool openFileForReading(uint8_t *fileName); 128 | uint32_t getFileSize(); 129 | uint16_t getNextFileBlock(); 130 | bool isLastBlock(); 131 | 132 | void openFileForWriting(uint8_t *fileName); 133 | void writeBufferToFile(uint16_t bytesToWrite); 134 | void updateBlock(); 135 | void closeFile(); 136 | bool isLongFilename(); 137 | bool isHidden(); 138 | bool isVolumeId(); 139 | bool isDirectory(); 140 | uint8_t* getFilename(); 141 | bool openDirectory(const char* dirName); 142 | void openCurrentDirectory(); 143 | uint8_t* getBuffer(); 144 | 145 | bool findFile(char* fileName); 146 | void deleteFile(); 147 | uint32_t seek(uint32_t pos); 148 | 149 | void setDateTime(int year, int month, int day, int hour, int minute, int second); 150 | 151 | uint16_t writeBufferSize() 152 | { 153 | return 512; 154 | } 155 | 156 | bool needRealTime() 157 | { 158 | return true; 159 | } 160 | 161 | private: 162 | SD* _sd; 163 | uint8_t* _FatBuffer; 164 | uint8_t* _longEntryString; 165 | SerialLogger* _logger; 166 | file_position _filePosition; 167 | struct dir_Structure* _currentDirectoryEntry; 168 | bool _initialized; 169 | 170 | bool _indexed; 171 | uint32_t _fileClusterIndex[64]; 172 | 173 | uint32_t _firstDataSector; 174 | uint32_t _rootCluster; 175 | 176 | uint16_t _timeValue; 177 | uint16_t _dateValue; 178 | 179 | uint32_t _totalClusters; 180 | uint16_t _bytesPerSector; 181 | uint16_t _sectorPerCluster; 182 | uint16_t _reservedSectorCount; 183 | uint32_t _unusedSectors; 184 | uint32_t _appendFileSector; 185 | uint32_t _appendFileLocation; 186 | uint32_t _fileSize; 187 | uint32_t _appendStartCluster; 188 | 189 | //flag to keep track of free cluster count updating in FSinfo sector 190 | uint8_t _freeClusterCountUpdated; 191 | uint32_t _fileStartCluster; 192 | 193 | uint32_t _currentDirectoryCluster; 194 | 195 | uint32_t getRootCluster(); 196 | uint8_t getBootSectorData (void); 197 | uint32_t getFirstSector(uint32_t clusterNumber); 198 | uint32_t getSetFreeCluster(uint8_t totOrNext, uint8_t get_set, uint32_t FSEntry); 199 | 200 | uint32_t getSetNextCluster (uint32_t clusterNumber,uint8_t get_set,uint32_t clusterEntry); 201 | uint8_t readFile (uint8_t flag, uint8_t *fileName); 202 | 203 | void convertToShortFilename(uint8_t *input, uint8_t *output); 204 | void writeFile (uint8_t *fileName); 205 | uint32_t searchNextFreeCluster (uint32_t startCluster); 206 | void freeMemoryUpdate (uint8_t flag, uint32_t size); 207 | 208 | void startFileRead(struct dir_Structure *dirEntry, file_stat *thisFileStat); 209 | void getCurrentFileBlock(file_stat *thisFileStat); 210 | uint32_t getNextBlockAddress(file_stat *thisFileStat); 211 | 212 | uint32_t getFirstCluster(struct dir_Structure *dir); 213 | void makeShortFilename(uint8_t *longFilename, uint8_t *shortFilename); 214 | 215 | uint8_t ChkSum (uint8_t *pFcbName); 216 | uint8_t isLongFilename(uint8_t *fileName); 217 | uint8_t numCharsToCompare(uint8_t *fileName, uint8_t maxChars); 218 | 219 | bool findFile(char* fileName, uint32_t firstCluster); 220 | void indexFileForSeeking(); 221 | 222 | void copyShortFilename(); 223 | }; 224 | 225 | } 226 | 227 | #endif 228 | -------------------------------------------------------------------------------- /legacy/src/IEEE488.h: -------------------------------------------------------------------------------- 1 | /* 2 | IEEE488.h 3 | IEEE Routines in the PETdisk storage device 4 | Copyright (C) 2011 Michael Hill 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | 19 | Contact the author at bitfixer@bitfixer.com 20 | http://bitfixer.com 21 | */ 22 | 23 | #ifndef _IEEE488_H 24 | #define _IEEE488_H 25 | 26 | #include "SerialLogger.h" 27 | #include 28 | 29 | #define TALK 0x40 30 | #define LISTEN 0x20 31 | 32 | #define UNTALK 0x5F 33 | #define UNLISTEN 0x3F 34 | 35 | typedef enum { 36 | ATN = 0x01, 37 | NDAC = 0x02, 38 | DAV = 0x04, 39 | NRFD = 0x08, 40 | EOI = 0x10 41 | } IEEEBusSignal; 42 | 43 | namespace bitfixer { 44 | 45 | class IEEE488 { 46 | public: 47 | IEEE488() 48 | : _logger(NULL) 49 | , _atn_low(false) 50 | , _eoi_low(false) 51 | , _unlistened(false) 52 | {} 53 | 54 | IEEE488(SerialLogger* logger) 55 | : _logger(logger) 56 | , _atn_low(false) 57 | , _eoi_low(false) 58 | , _unlistened(false) 59 | {} 60 | 61 | ~IEEE488() {} 62 | 63 | void initWithLogger(SerialLogger* logger); 64 | void sendIEEEBytes(uint8_t *entry, int size, uint8_t isLast); 65 | uint8_t sendIEEEByteCheckForATN(uint8_t byte); 66 | uint8_t sendIEEEByteCheckForATN2(uint8_t byte, bool last); 67 | void unlisten(); 68 | bool is_unlistened(); 69 | void begin_output(); 70 | void end_output(); 71 | 72 | uint8_t get_byte_from_bus(); 73 | void acknowledge_bus_byte(); 74 | bool atn_is_low(); 75 | bool eoi_is_low(); 76 | void signal_ready_for_data(); 77 | 78 | void raise_dav_and_eoi(); 79 | uint8_t wait_for_ndac_low_or_atn_low(); 80 | IEEEBusSignal wait_for_ndac_high_or_atn_low(); 81 | uint8_t wait_for_nrfd_high_or_atn_low(); 82 | bool is_atn_asserted(); 83 | void wait_for_atn_low(); 84 | void wait_for_dav_low(); 85 | void recv_byte(uint8_t *byte); 86 | 87 | uint8_t get_device_address(uint8_t* dir, bool* success); 88 | void accept_address(); 89 | void reject_address(); 90 | 91 | void set_data_output(); 92 | void set_data_input(); 93 | 94 | void write_byte_to_data_bus(uint8_t byte); 95 | private: 96 | SerialLogger* _logger; 97 | bool _atn_low; 98 | bool _eoi_low; 99 | 100 | bool _unlistened; 101 | 102 | void wait_for_atn_high(); 103 | void wait_for_dav_high(); 104 | 105 | void wait_for_nrfd_high(); 106 | void wait_for_nrfd_low(); 107 | void wait_for_ndac_high(); 108 | void wait_for_ndac_low(); 109 | void send_byte(uint8_t byte, int last); 110 | 111 | /* 112 | void set_nrfd_input(); 113 | void set_nrfd_output(); 114 | void set_ndac_input(); 115 | void set_ndac_output(); 116 | void set_dav_input(); 117 | void set_dav_output(); 118 | void set_eoi_input(); 119 | void set_eoi_output(); 120 | */ 121 | 122 | }; 123 | 124 | } 125 | 126 | #endif -------------------------------------------------------------------------------- /legacy/src/Logger.h: -------------------------------------------------------------------------------- 1 | #ifndef __logger_h__ 2 | #define __logger_h__ 3 | 4 | #include 5 | #include 6 | 7 | #define LOG_BUFFER_SIZE 64 8 | static char _line[LOG_BUFFER_SIZE]; 9 | 10 | class Logger { 11 | public: 12 | Logger() {} 13 | ~Logger() {} 14 | 15 | virtual void init() {} 16 | virtual void log(const char* str) {} 17 | virtual void log(unsigned char* data, int length) {} 18 | virtual void logF(const char* str) {} 19 | virtual void printf(const char* format, ...) 20 | { 21 | va_list vl; 22 | va_start(vl, format); 23 | vsprintf(_line, format, vl); 24 | log(_line); 25 | } 26 | virtual void flush() {} 27 | }; 28 | 29 | #endif -------------------------------------------------------------------------------- /legacy/src/NetworkDataSource.h: -------------------------------------------------------------------------------- 1 | #ifndef __network_data_source_h__ 2 | #define __network_data_source_h__ 3 | 4 | #include "DataSource.h" 5 | #include "EspHttp.h" 6 | #include "SerialLogger.h" 7 | #include "Settings.h" 8 | 9 | namespace bitfixer { 10 | 11 | class NetworkDataSource : public DataSource 12 | { 13 | public: 14 | NetworkDataSource() 15 | : _http(NULL) 16 | , _fileSize(0) 17 | , _currentBlockByte(0) 18 | , _currentOutputByte(0) 19 | , _currentDirectoryPage(0) 20 | , _blockData(0) 21 | , _dataBuffer(NULL) 22 | , _dataBufferSize(NULL) 23 | , _dirPtr(0) 24 | , _log(NULL) 25 | , _firstBlockWritten(false) 26 | , _readBufferSize(512) 27 | , _writeBufferSize(512) 28 | {} 29 | 30 | NetworkDataSource(EspHttp* http, uint8_t* buffer, uint16_t* bufferSize, Logger* log) 31 | : _http(http) 32 | , _fileSize(0) 33 | , _currentBlockByte(0) 34 | , _currentOutputByte(0) 35 | , _currentDirectoryPage(0) 36 | , _blockData(0) 37 | , _dataBuffer(buffer) 38 | , _dataBufferSize(bufferSize) 39 | , _dirPtr(0) 40 | , _log(log) 41 | , _firstBlockWritten(false) 42 | , _readBufferSize(512) 43 | , _writeBufferSize(512) 44 | { 45 | struct urlInfo* urlInfo = (struct urlInfo*)_dataBuffer; 46 | _fileName = urlInfo->fileName; 47 | } 48 | 49 | ~NetworkDataSource() {} 50 | 51 | void initWithParams(EspHttp* http, uint8_t* buffer, uint16_t* bufferSize, Logger* log) 52 | { 53 | _http = http; 54 | _dataBuffer = buffer; 55 | _dataBufferSize = bufferSize; 56 | _log = log; 57 | 58 | struct urlInfo* urlInfo = (struct urlInfo*)_dataBuffer; 59 | _fileName = urlInfo->fileName; 60 | } 61 | 62 | void setUrlData(void* eepromHost, int eepromHostLength, int port, void* eepromUrl, int eepromUrlLength) 63 | { 64 | _settings.initWithParams(eepromHost, eepromHostLength, port, eepromUrl, eepromUrlLength); 65 | } 66 | 67 | bool init(); 68 | bool isInitialized(); 69 | void openFileForWriting(unsigned char* fileName); 70 | bool openFileForReading(unsigned char* fileName); 71 | bool openDirectory(const char* dirName); 72 | uint16_t getNextFileBlock(); 73 | bool isLastBlock(); 74 | bool getNextDirectoryEntry(); 75 | 76 | void writeBufferToFile(uint16_t numBytes); 77 | void updateBlock(); 78 | void closeFile(); 79 | void openCurrentDirectory(); 80 | bool isDirectory() { return false; } 81 | unsigned char* getFilename(); 82 | unsigned char* getBuffer(); 83 | 84 | bool getCurrentDateTime(int* year, int* month, int* day, int* hour, int* minute, int* second); 85 | 86 | uint32_t seek(uint32_t pos); 87 | 88 | uint16_t readBufferSize() 89 | { 90 | return _readBufferSize; 91 | } 92 | 93 | uint16_t writeBufferSize() 94 | { 95 | return _writeBufferSize; 96 | } 97 | 98 | uint16_t requestReadBufferSize(uint16_t requestedReadBufferSize); 99 | uint16_t requestWriteBufferSize(uint16_t requestedWriteBufferSize); 100 | 101 | Settings _settings; 102 | private: 103 | EspHttp* _http; 104 | uint32_t _fileSize; 105 | uint32_t _currentBlockByte; 106 | uint32_t _currentOutputByte; 107 | int _currentDirectoryPage; 108 | uint8_t* _blockData; 109 | uint8_t* _dataBuffer; 110 | uint16_t* _dataBufferSize; 111 | char* _fileName; 112 | uint8_t* _dirPtr; 113 | Logger* _log; 114 | bool _firstBlockWritten; 115 | 116 | uint16_t _readBufferSize; 117 | uint16_t _writeBufferSize; 118 | 119 | bool fetchBlock(uint32_t start, uint32_t end); 120 | void copyUrlEscapedString(char* dest, char* src); 121 | }; 122 | 123 | } 124 | 125 | #endif -------------------------------------------------------------------------------- /legacy/src/SD_routines.h: -------------------------------------------------------------------------------- 1 | /* 2 | sd_routines.h 3 | SD Routines in the PETdisk storage device 4 | Copyright (C) 2011 Michael Hill 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | 19 | Contact the author at bitfixer@bitfixer.com 20 | http://bitfixer.com 21 | 22 | */ 23 | #ifndef _SD_ROUTINES_H_ 24 | #define _SD_ROUTINES_H_ 25 | 26 | #include 27 | #include "SPI_routines.h" 28 | 29 | //Use following macro if you don't want to activate the multiple block access functions 30 | //those functions are not required for FAT32 31 | 32 | #define FAT_TESTING_ONLY 33 | 34 | //SD commands, many of these are not used here 35 | #define GO_IDLE_STATE 0 36 | #define SEND_OP_COND 1 37 | #define SEND_IF_COND 8 38 | #define SEND_CSD 9 39 | #define STOP_TRANSMISSION 12 40 | #define SEND_STATUS 13 41 | #define SET_BLOCK_LEN 16 42 | #define READ_SINGLE_BLOCK 17 43 | #define READ_MULTIPLE_BLOCKS 18 44 | #define WRITE_SINGLE_BLOCK 24 45 | #define WRITE_MULTIPLE_BLOCKS 25 46 | #define ERASE_BLOCK_START_ADDR 32 47 | #define ERASE_BLOCK_END_ADDR 33 48 | #define ERASE_SELECTED_BLOCKS 38 49 | #define SD_SEND_OP_COND 41 //ACMD 50 | #define APP_CMD 55 51 | #define READ_OCR 58 52 | #define CRC_ON_OFF 59 53 | 54 | #define ON 1 55 | #define OFF 0 56 | 57 | class SD 58 | { 59 | public: 60 | SD() 61 | : _spi(NULL) 62 | , _startBlock(0) 63 | , _totalBlocks(0) 64 | , _SDHC_flag(0) 65 | , _cardType(0) 66 | , _cs(0) 67 | { 68 | 69 | } 70 | 71 | SD(bSPI* spi, int cs) 72 | : _spi(spi) 73 | , _startBlock(0) 74 | , _totalBlocks(0) 75 | , _SDHC_flag(0) 76 | , _cardType(0) 77 | , _cs(cs) 78 | { 79 | } 80 | 81 | ~SD() 82 | { 83 | _spi = 0; 84 | } 85 | 86 | uint8_t init(); 87 | uint8_t initWithSPI(bSPI* spi, int cs); 88 | uint8_t sendCommand(uint8_t cmd, uint32_t arg); 89 | uint8_t readSingleBlock(uint32_t startBlock, uint8_t* buffer); 90 | uint8_t writeSingleBlock(uint32_t startBlock, uint8_t* buffer); 91 | 92 | private: 93 | bSPI* _spi; 94 | uint32_t _startBlock; 95 | uint32_t _totalBlocks; 96 | uint8_t _SDHC_flag; 97 | uint8_t _cardType; 98 | int _cs; 99 | 100 | void cs_select(); 101 | void cs_unselect(); 102 | 103 | }; 104 | 105 | #endif 106 | -------------------------------------------------------------------------------- /legacy/src/SPI_routines.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | SPI_routines.c 3 | SPI Routines in the PETdisk storage device 4 | Copyright (C) 2011 Michael Hill 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | 19 | Contact the author at bitfixer@bitfixer.com 20 | http://bitfixer.com 21 | */ 22 | #include "SPI_routines.h" 23 | #include "hardware.h" 24 | 25 | void bSPI::init() 26 | { 27 | spi_init(); 28 | } 29 | 30 | uint8_t bSPI::transmit(uint8_t data) 31 | { 32 | return spi_transmit(data); 33 | } 34 | 35 | uint8_t bSPI::receive() 36 | { 37 | return transmit(0xff); 38 | } 39 | 40 | void bSPI::cs_select() 41 | { 42 | spi_cs_select(); 43 | } 44 | 45 | void bSPI::cs_unselect() 46 | { 47 | spi_cs_unselect(); 48 | } 49 | -------------------------------------------------------------------------------- /legacy/src/SPI_routines.h: -------------------------------------------------------------------------------- 1 | #ifndef _SPI_ROUTINES_H_ 2 | #define _SPI_ROUTINES_H_ 3 | 4 | #include 5 | 6 | class bSPI { 7 | public: 8 | bSPI() {} 9 | ~bSPI() {} 10 | 11 | void init(); 12 | uint8_t transmit(uint8_t data); 13 | uint8_t receive(); 14 | 15 | void cs_select(); 16 | void cs_unselect(); 17 | }; 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /legacy/src/Serial.cpp: -------------------------------------------------------------------------------- 1 | #include "Serial.h" 2 | #include "hardware.h" 3 | #include 4 | 5 | namespace bitfixer { 6 | 7 | // Serial Port 0 8 | void Serial0::init(uint32_t baudRate) 9 | { 10 | serial0_init(baudRate); 11 | } 12 | 13 | void Serial0::transmitByte(unsigned char data) 14 | { 15 | serial0_transmitByte(data); 16 | } 17 | 18 | unsigned char Serial0::receiveByte() 19 | { 20 | return serial0_receiveByte(); 21 | } 22 | 23 | void Serial0::enable_interrupt() 24 | { 25 | serial0_enable_interrupt(); 26 | } 27 | 28 | void Serial0::disable_interrupt() 29 | { 30 | serial0_disable_interrupt(); 31 | } 32 | 33 | 34 | // Serial Port 1 35 | void Serial1::init(uint32_t baudRate) 36 | { 37 | serial1_init(baudRate); 38 | } 39 | 40 | void Serial1::transmitByte(unsigned char data) 41 | { 42 | serial1_transmitByte(data); 43 | } 44 | 45 | unsigned char Serial1::receiveByte() 46 | { 47 | return serial1_receiveByte(); 48 | } 49 | 50 | void Serial1::enable_interrupt() 51 | { 52 | serial1_enable_interrupt(); 53 | } 54 | 55 | void Serial1::disable_interrupt() 56 | { 57 | serial1_disable_interrupt(); 58 | } 59 | 60 | 61 | // shared 62 | void Serial::transmitString(const char* str) 63 | { 64 | while (*str != 0) 65 | { 66 | transmitByte(*str++); 67 | } 68 | } 69 | 70 | void Serial::transmitStringF(const char* string) 71 | { 72 | uint8_t* str = (uint8_t*)string; 73 | while (bf_pgm_read_byte(&(*str))) 74 | { 75 | transmitByte(bf_pgm_read_byte(&(*str++))); 76 | } 77 | } 78 | 79 | } -------------------------------------------------------------------------------- /legacy/src/Serial.h: -------------------------------------------------------------------------------- 1 | #ifndef __serial_h__ 2 | #define __serial_h__ 3 | 4 | #include 5 | 6 | namespace bitfixer 7 | { 8 | 9 | class Serial { 10 | public: 11 | Serial() {} 12 | ~Serial() {} 13 | 14 | virtual void init(uint32_t baudRate); 15 | virtual void transmitByte(unsigned char data) = 0; 16 | virtual unsigned char receiveByte() = 0; 17 | virtual void transmitString(const char* string); 18 | virtual void transmitStringF(const char* string); 19 | virtual void enable_interrupt() = 0; 20 | virtual void disable_interrupt() = 0; 21 | }; 22 | 23 | class Serial0 : public Serial { 24 | public: 25 | Serial0() {} 26 | ~Serial0() {} 27 | 28 | void init(uint32_t baudRate); 29 | void transmitByte(unsigned char data); 30 | unsigned char receiveByte(); 31 | void enable_interrupt(); 32 | void disable_interrupt(); 33 | }; 34 | 35 | class Serial1 : public Serial { 36 | public: 37 | Serial1() {} 38 | ~Serial1() {} 39 | 40 | void init(uint32_t baudRate); 41 | void transmitByte(unsigned char data); 42 | unsigned char receiveByte(); 43 | void enable_interrupt(); 44 | void disable_interrupt(); 45 | }; 46 | 47 | } 48 | 49 | #endif -------------------------------------------------------------------------------- /legacy/src/SerialLogger.h: -------------------------------------------------------------------------------- 1 | #ifndef __serial_logger_h__ 2 | #define __serial_logger_h__ 3 | 4 | #include "Logger.h" 5 | #include "Serial.h" 6 | #include 7 | 8 | namespace bitfixer 9 | { 10 | 11 | class SerialLogger : public Logger { 12 | public: 13 | SerialLogger() 14 | : _serial(NULL) { 15 | 16 | } 17 | 18 | SerialLogger(Serial* serial) 19 | : _serial(serial) { 20 | 21 | } 22 | 23 | void init() 24 | { 25 | } 26 | 27 | void initWithSerial(Serial* serial) 28 | { 29 | _serial = serial; 30 | } 31 | 32 | void log(const char* str) 33 | { 34 | _serial->transmitString(str); 35 | } 36 | 37 | void log(unsigned char* data, int length) 38 | { 39 | for (int l = 0; l < length; l++) 40 | { 41 | _serial->transmitByte(data[l]); 42 | } 43 | } 44 | 45 | void logF(const char* str) 46 | { 47 | _serial->transmitStringF(str); 48 | } 49 | 50 | private: 51 | Serial* _serial; 52 | }; 53 | 54 | class BufferedSerialLogger : public Logger { 55 | public: 56 | BufferedSerialLogger(Serial* serial) 57 | : _serial(serial) 58 | , _bufferPos(0) { 59 | 60 | } 61 | 62 | void init() 63 | { 64 | } 65 | 66 | void log(const char* str) 67 | { 68 | 69 | } 70 | 71 | void log(unsigned char* data, int length) 72 | { 73 | 74 | } 75 | 76 | void logF(const char* str) 77 | { 78 | 79 | } 80 | 81 | void flush() 82 | { 83 | 84 | } 85 | 86 | private: 87 | Serial* _serial; 88 | char _logBuffer[LOG_BUFFER_SIZE]; 89 | unsigned int _bufferPos; 90 | }; 91 | 92 | } 93 | 94 | #endif -------------------------------------------------------------------------------- /legacy/src/Settings.cpp: -------------------------------------------------------------------------------- 1 | #include "Settings.h" 2 | #include 3 | #include 4 | #include "hardware.h" 5 | 6 | void Settings::initWithParams(void* eepromHost, int eepromHostLength, int port, void* eepromUrl, int eepromUrlLength) 7 | { 8 | _urlData.eepromHost = eepromHost; 9 | _urlData.eepromHostLength = eepromHostLength; 10 | _urlData.port = port; 11 | _urlData.eepromUrl = eepromUrl; 12 | _urlData.eepromUrlLength = eepromUrlLength; 13 | } 14 | 15 | int Settings::getUrl(char* url) 16 | { 17 | bf_eeprom_read_block(url, _urlData.eepromUrl, _urlData.eepromUrlLength); 18 | url[_urlData.eepromUrlLength] = 0; 19 | return _urlData.eepromUrlLength; 20 | } 21 | 22 | int Settings::getHost(char* host) 23 | { 24 | bf_eeprom_read_block(host, _urlData.eepromHost, _urlData.eepromHostLength); 25 | host[_urlData.eepromHostLength] = 0; 26 | return _urlData.eepromHostLength; 27 | } 28 | 29 | int Settings::getPort() 30 | { 31 | return _urlData.port; 32 | } -------------------------------------------------------------------------------- /legacy/src/Settings.h: -------------------------------------------------------------------------------- 1 | #ifndef __settings_h__ 2 | #define __settings_h__ 3 | 4 | struct urlData 5 | { 6 | void* eepromHost; 7 | int eepromHostLength; 8 | int port; 9 | void* eepromUrl; 10 | int eepromUrlLength; 11 | }; 12 | 13 | class Settings { 14 | public: 15 | Settings() {}; 16 | ~Settings() {}; 17 | 18 | void initWithParams(void* eepromHost, int eepromHostLength, int port, void* eepromUrl, int eepromUrlLength); 19 | int getUrl(char* url); 20 | int getHost(char* host); 21 | int getPort(); 22 | 23 | private: 24 | urlData _urlData; 25 | }; 26 | 27 | #endif -------------------------------------------------------------------------------- /legacy/src/avr/avr_main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | extern uint8_t _buffer[1024]; 4 | extern uint16_t _bufferSize; 5 | 6 | extern void setup(); 7 | extern void loop(); 8 | 9 | int main(void) 10 | { 11 | setup(); 12 | while(1) { 13 | loop(); 14 | } 15 | } 16 | 17 | // interrupt handler - should read bytes into a buffer. 18 | // this can be read outside the handler to check for end tokens 19 | // would need to be consumed fast enough to prevent buffer overrun 20 | // length can be an atomic (8-bit) value 21 | // you are guaranteed to be able to read this amount of data 22 | // if you allocate enough space to handle any potential reads, you 23 | // don't even need a ring buffer, just a regular buffer 24 | 25 | // turn on serial interrupts to start reading 26 | // turn off when done 27 | ISR(USART0_RX_vect) 28 | { 29 | // insert character into buffer 30 | // loop to beginning if needed 31 | uint8_t a = UDR0; 32 | _buffer[_bufferSize] = a; 33 | _bufferSize++; 34 | } -------------------------------------------------------------------------------- /legacy/src/avr/bootloader/DataSource.h: -------------------------------------------------------------------------------- 1 | #ifndef __datasource_h__ 2 | #define __datasource_h__ 3 | 4 | #include 5 | 6 | class DataSource 7 | { 8 | public: 9 | DataSource() {} 10 | ~DataSource() {} 11 | 12 | virtual bool init() = 0; 13 | virtual void openFileForWriting(unsigned char* fileName) = 0; 14 | virtual bool openFileForReading(unsigned char* fileName) = 0; 15 | virtual bool openDirectory(const char* dirName) = 0; 16 | virtual unsigned int getNextFileBlock() = 0; 17 | virtual bool isLastBlock() = 0; 18 | virtual bool getNextDirectoryEntry() = 0; 19 | virtual bool isInitialized() = 0; 20 | virtual void writeBufferToFile(unsigned int numBytes) = 0; 21 | virtual void updateBlock() {} 22 | virtual void closeFile() = 0; 23 | virtual void openCurrentDirectory() = 0; 24 | virtual uint32_t seek(uint32_t pos) { return 0; } 25 | virtual bool isHidden() { return false; } 26 | virtual bool isVolumeId() { return false; } 27 | virtual bool isDirectory() { return false; } 28 | virtual unsigned char* getFilename() = 0; 29 | virtual unsigned char* getBuffer() = 0; 30 | virtual unsigned int writeBufferSize() = 0; 31 | virtual unsigned int readBufferSize() { return 512; } 32 | virtual unsigned int requestReadBufferSize(unsigned int requestedReadBufferSize) { 33 | // default to not changing read buffer size 34 | return 512; 35 | } 36 | virtual unsigned int requestWriteBufferSize(unsigned int requestedWriteBufferSize) { 37 | return 512; 38 | } 39 | 40 | virtual void processCommandString(int* address) {} // default no action 41 | }; 42 | 43 | #endif -------------------------------------------------------------------------------- /legacy/src/avr/bootloader/FAT32_tiny.h: -------------------------------------------------------------------------------- 1 | /* 2 | FAT32.h 3 | FAT32 filesystem Routines in the PETdisk storage device 4 | Copyright (C) 2011 Michael Hill 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | 19 | Contact the author at bitfixer@bitfixer.com 20 | http://bitfixer.com 21 | */ 22 | 23 | #ifndef _FAT32_H_ 24 | #define _FAT32_H_ 25 | 26 | #include "SD_routines.h" 27 | #include "SerialLogger.h" 28 | #include "DataSource.h" 29 | 30 | //Structure to access Directory Entry in the FAT 31 | struct dir_Structure{ 32 | unsigned char name[11]; //0 33 | unsigned char attrib; //11 //file attributes 34 | unsigned char NTreserved; //12 //always 0 35 | unsigned char timeTenth; //13 //tenths of seconds, set to 0 here 36 | unsigned int createTime; //14 //time file was created 37 | unsigned int createDate; //16 //date file was created 38 | unsigned int lastAccessDate;//18 39 | unsigned int firstClusterHI;//20 //higher word of the first cluster number 40 | unsigned int writeTime; //22 //time of last write 41 | unsigned int writeDate; //24 //date of last write 42 | unsigned int firstClusterLO;//26 //lower word of the first cluster number 43 | unsigned long fileSize; //28 //size of file in bytes 44 | //32 45 | }; 46 | 47 | // structure for file read information 48 | typedef struct _file_stat{ 49 | unsigned long currentCluster; 50 | unsigned long fileSize; 51 | unsigned long currentSector; 52 | unsigned long byteCounter; 53 | int sectorIndex; 54 | } file_stat; 55 | 56 | typedef struct _file_position { 57 | unsigned char isLongFilename; 58 | unsigned char *fileName; 59 | unsigned long startCluster; 60 | unsigned long cluster; 61 | unsigned long dirStartCluster; 62 | unsigned char sectorIndex; 63 | unsigned long sector; 64 | unsigned long fileSize; 65 | unsigned long byteCounter; 66 | unsigned int byte; 67 | unsigned char shortFilename[11]; 68 | } file_position; 69 | 70 | #define MAX_FILENAME 256 71 | 72 | class FAT32 73 | { 74 | public: 75 | FAT32(SD* sd, unsigned char* fatbuffer) 76 | : _sd(sd) 77 | , _FatBuffer(fatbuffer) 78 | , _currentDirectoryEntry(0) 79 | { 80 | 81 | } 82 | 83 | ~FAT32() {} 84 | 85 | bool init(); 86 | 87 | void openDirectory(); 88 | bool getNextDirectoryEntry(); 89 | bool openFileForReading(); 90 | unsigned int getNextFileBlock(); 91 | bool isLastBlock(); 92 | unsigned char* getShortFilename(); 93 | 94 | private: 95 | SD* _sd; 96 | unsigned char* _FatBuffer; 97 | file_position _filePosition; 98 | struct dir_Structure* _currentDirectoryEntry; 99 | 100 | unsigned long _firstDataSector; 101 | unsigned long _rootCluster; 102 | unsigned long _totalClusters; 103 | unsigned int _bytesPerSector; 104 | unsigned int _sectorPerCluster; 105 | unsigned int _reservedSectorCount; 106 | unsigned long _unusedSectors; 107 | unsigned long _appendFileSector; 108 | unsigned long _appendFileLocation; 109 | unsigned long _fileSize; 110 | unsigned long _appendStartCluster; 111 | 112 | unsigned long _fileStartCluster; 113 | unsigned long _currentDirectoryCluster; 114 | 115 | unsigned char getBootSectorData (void); 116 | unsigned long getFirstSector(unsigned long clusterNumber); 117 | 118 | unsigned long getNextCluster (unsigned long clusterNumber ,unsigned long clusterEntry); 119 | unsigned long getFirstCluster(struct dir_Structure *dir); 120 | }; 121 | 122 | #endif 123 | -------------------------------------------------------------------------------- /legacy/src/avr/bootloader/Logger.h: -------------------------------------------------------------------------------- 1 | #ifndef __logger_h__ 2 | #define __logger_h__ 3 | 4 | #include 5 | #include 6 | 7 | #define LOG_BUFFER_SIZE 64 8 | static char _line[LOG_BUFFER_SIZE]; 9 | 10 | class Logger { 11 | public: 12 | Logger() {} 13 | ~Logger() {} 14 | 15 | virtual void init() {} 16 | virtual void log(const char* str) {} 17 | virtual void log(unsigned char* data, int length) {} 18 | virtual void logF(const char* str) {} 19 | virtual void printf(const char* format, ...) 20 | { 21 | va_list vl; 22 | va_start(vl, format); 23 | vsprintf(_line, format, vl); 24 | log(_line); 25 | } 26 | virtual void flush() {} 27 | }; 28 | 29 | #endif -------------------------------------------------------------------------------- /legacy/src/avr/bootloader/SD_routines.h: -------------------------------------------------------------------------------- 1 | /* 2 | sd_routines.h 3 | SD Routines in the PETdisk storage device 4 | Copyright (C) 2011 Michael Hill 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | 19 | Contact the author at bitfixer@bitfixer.com 20 | http://bitfixer.com 21 | 22 | */ 23 | #ifndef _SD_ROUTINES_H_ 24 | #define _SD_ROUTINES_H_ 25 | 26 | #include "SPI_routines.h" 27 | 28 | //Use following macro if you don't want to activate the multiple block access functions 29 | //those functions are not required for FAT32 30 | 31 | #define FAT_TESTING_ONLY 32 | 33 | //SD commands, many of these are not used here 34 | #define GO_IDLE_STATE 0 35 | #define SEND_OP_COND 1 36 | #define SEND_IF_COND 8 37 | #define SEND_CSD 9 38 | #define STOP_TRANSMISSION 12 39 | #define SEND_STATUS 13 40 | #define SET_BLOCK_LEN 16 41 | #define READ_SINGLE_BLOCK 17 42 | #define READ_MULTIPLE_BLOCKS 18 43 | #define WRITE_SINGLE_BLOCK 24 44 | #define WRITE_MULTIPLE_BLOCKS 25 45 | #define ERASE_BLOCK_START_ADDR 32 46 | #define ERASE_BLOCK_END_ADDR 33 47 | #define ERASE_SELECTED_BLOCKS 38 48 | #define SD_SEND_OP_COND 41 //ACMD 49 | #define APP_CMD 55 50 | #define READ_OCR 58 51 | #define CRC_ON_OFF 59 52 | 53 | #define ON 1 54 | #define OFF 0 55 | 56 | class SD 57 | { 58 | public: 59 | SD(SPI* spi, int cs) 60 | : _spi(spi) 61 | , _startBlock(0) 62 | , _totalBlocks(0) 63 | , _SDHC_flag(0) 64 | , _cardType(0) 65 | , _cs(cs) 66 | { 67 | } 68 | 69 | ~SD() 70 | { 71 | _spi = 0; 72 | } 73 | 74 | unsigned char init(); 75 | unsigned char sendCommand(unsigned char cmd, unsigned long arg); 76 | unsigned char readSingleBlock(unsigned long startBlock, unsigned char* buffer); 77 | unsigned char writeSingleBlock(unsigned long startBlock, unsigned char* buffer); 78 | 79 | private: 80 | SPI* _spi; 81 | unsigned long _startBlock; 82 | unsigned long _totalBlocks; 83 | unsigned char _SDHC_flag; 84 | unsigned char _cardType; 85 | int _cs; 86 | 87 | void cs_select(); 88 | void cs_unselect(); 89 | 90 | }; 91 | 92 | #endif 93 | -------------------------------------------------------------------------------- /legacy/src/avr/bootloader/SPI_routines.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | SPI_routines.c 3 | SPI Routines in the PETdisk storage device 4 | Copyright (C) 2011 Michael Hill 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | 19 | Contact the author at bitfixer@bitfixer.com 20 | http://bitfixer.com 21 | */ 22 | #include "SPI_routines.h" 23 | 24 | void SPI::init() 25 | { 26 | SPI_PORT = 0x00; 27 | SPI_PORT |= 1 << SPI_CS; 28 | SPI_PORT |= 1 << SPI_CS2; 29 | SPI_CONTROL |= 1 << SPI_CS; 30 | SPI_CONTROL |= 1 << SPI_CS2; 31 | SPI_CONTROL |= 1 << SPI_MOSI; 32 | SPI_CONTROL |= 1 << SPI_SCK; 33 | 34 | SPCR = 0x52; 35 | SPSR = 0x00; 36 | } 37 | 38 | uint8_t SPI::transmit(uint8_t data) 39 | { 40 | SPDR = data; 41 | while ( !(SPSR & (1<. 18 | 19 | Contact the author at bitfixer@bitfixer.com 20 | http://bitfixer.com 21 | */ 22 | #ifndef _SPI_ROUTINES_H_ 23 | #define _SPI_ROUTINES_H_ 24 | 25 | #include 26 | #include 27 | 28 | #define SPI_CONTROL DDRB 29 | #define SPI_PORT PORTB 30 | #define SPI_CS PB4 31 | #define SPI_CS2 PB3 32 | #define SPI_MOSI PB5 33 | #define SPI_SCK PB7 34 | 35 | class SPI { 36 | public: 37 | SPI() {} 38 | ~SPI() {} 39 | 40 | void init(); 41 | uint8_t transmit(uint8_t data); 42 | uint8_t receive(); 43 | }; 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /legacy/src/avr/bootloader/Serial.h: -------------------------------------------------------------------------------- 1 | #ifndef __serial_h__ 2 | #define __serial_h__ 3 | 4 | class Serial { 5 | public: 6 | Serial() {} 7 | ~Serial() {} 8 | 9 | virtual void init(unsigned int ubrr, bool double_speed); 10 | virtual void transmitByte(unsigned char data) = 0; 11 | virtual unsigned char receiveByte() = 0; 12 | virtual void transmitString(const char* string); 13 | virtual void transmitStringF(const char* string); 14 | virtual void enable_interrupt() = 0; 15 | virtual void disable_interrupt() = 0; 16 | }; 17 | 18 | class Serial0 : public Serial { 19 | public: 20 | Serial0() {} 21 | ~Serial0() {} 22 | 23 | void init(unsigned int ubrr, bool double_speed = false); 24 | void transmitByte(unsigned char data); 25 | unsigned char receiveByte(); 26 | void enable_interrupt(); 27 | void disable_interrupt(); 28 | }; 29 | 30 | class Serial1 : public Serial { 31 | public: 32 | Serial1() {} 33 | ~Serial1() {} 34 | 35 | void init(unsigned int ubrr, bool double_speed = false); 36 | void transmitByte(unsigned char data); 37 | unsigned char receiveByte(); 38 | void enable_interrupt(); 39 | void disable_interrupt(); 40 | }; 41 | 42 | #endif -------------------------------------------------------------------------------- /legacy/src/avr/bootloader/SerialLogger.h: -------------------------------------------------------------------------------- 1 | #ifndef __serial_logger_h__ 2 | #define __serial_logger_h__ 3 | 4 | #include "Logger.h" 5 | #include "Serial.h" 6 | #include 7 | 8 | class SerialLogger : public Logger { 9 | public: 10 | SerialLogger(Serial* serial) 11 | : _serial(serial) { 12 | 13 | } 14 | 15 | void init() 16 | { 17 | } 18 | 19 | void log(const char* str) 20 | { 21 | _serial->transmitString(str); 22 | } 23 | 24 | void log(unsigned char* data, int length) 25 | { 26 | for (int l = 0; l < length; l++) 27 | { 28 | _serial->transmitByte(data[l]); 29 | } 30 | } 31 | 32 | void logF(const char* str) 33 | { 34 | _serial->transmitStringF(str); 35 | } 36 | 37 | private: 38 | Serial* _serial; 39 | }; 40 | 41 | class BufferedSerialLogger : public Logger { 42 | public: 43 | BufferedSerialLogger(Serial* serial) 44 | : _serial(serial) 45 | , _bufferPos(0) { 46 | 47 | } 48 | 49 | void init() 50 | { 51 | } 52 | 53 | void log(const char* str) 54 | { 55 | 56 | } 57 | 58 | void log(unsigned char* data, int length) 59 | { 60 | 61 | } 62 | 63 | void logF(const char* str) 64 | { 65 | 66 | } 67 | 68 | void flush() 69 | { 70 | 71 | } 72 | 73 | private: 74 | Serial* _serial; 75 | char _logBuffer[LOG_BUFFER_SIZE]; 76 | unsigned int _bufferPos; 77 | }; 78 | 79 | #endif -------------------------------------------------------------------------------- /legacy/src/avr/bootloader/bootloader.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "SPI_routines.h" 10 | #include "SD_routines.h" 11 | #include "FAT32_tiny.h" 12 | 13 | #include 14 | 15 | // offset should be 2*boot start word address 16 | // using 2048 word bootloader, boot start address is $3800 (word) 17 | // this is 0x7000 in bytes 18 | // linker param: -Ttext=0x7000 19 | 20 | // UART init 21 | void serial_init(unsigned int ubrr) 22 | { 23 | UBRR1H = (unsigned char)(ubrr>>8); 24 | UBRR1L = (unsigned char)ubrr; 25 | UCSR1A = 0x00; 26 | UCSR1B = (1<'); 164 | for (int i = 0; i < 11; i++) 165 | { 166 | serial_transmitByte(name[i]); 167 | } 168 | 169 | fat32.openFileForReading(); 170 | bytes = fat32.getNextFileBlock(); 171 | page = 0; 172 | while (bytes > 0) 173 | { 174 | for (int i = 0; i < 512; i += SPM_PAGESIZE) 175 | { 176 | boot_program_page(page, &buffer[i]); 177 | page += SPM_PAGESIZE; 178 | } 179 | 180 | bytes = fat32.getNextFileBlock(); 181 | } 182 | 183 | break; 184 | } 185 | 186 | serial_transmitByte('\r'); 187 | serial_transmitByte('\n'); 188 | } 189 | blink_led(1, 150, 150); 190 | } 191 | else 192 | { 193 | blink_led(3, 150, 150); 194 | } 195 | } 196 | 197 | int main() 198 | { 199 | load_firmware(); 200 | asm("jmp 0"); 201 | } -------------------------------------------------------------------------------- /legacy/src/avr/d64_test.cpp: -------------------------------------------------------------------------------- 1 | #include "D64DataSource.h" 2 | #include "fsDataSource.h" 3 | #include "ConsoleLogger.h" 4 | 5 | int main(int argc, char** argv) 6 | { 7 | D64DataSource d64ds; 8 | fsDataSource fsds; 9 | ConsoleLogger logger; 10 | logger.log("test\n"); 11 | 12 | fsds.init(); 13 | d64ds.initWithDataSource(&fsds, "test.d64", &logger); 14 | 15 | char fname[21]; 16 | for (int i = 0; i < 10; i++) 17 | { 18 | sprintf(fname, "FNAME%d.PRG", i); 19 | d64ds.openFileForWriting((unsigned char*)fname); 20 | 21 | uint8_t data[1024]; 22 | uint8_t* dptr = data; 23 | memset(data, 0xBB, 1024); 24 | 25 | int remainingBytes = 1024; 26 | while (remainingBytes > 0) 27 | { 28 | int bytesToSend = d64ds.writeBufferSize(); 29 | if (remainingBytes < bytesToSend) 30 | { 31 | bytesToSend = remainingBytes; 32 | } 33 | 34 | memcpy(d64ds.getBuffer(), dptr, bytesToSend); 35 | dptr += bytesToSend; 36 | remainingBytes -= bytesToSend; 37 | 38 | d64ds.writeBufferToFile(bytesToSend); 39 | } 40 | 41 | d64ds.closeFile(); 42 | } 43 | 44 | d64ds.openCurrentDirectory(); 45 | while (d64ds.getNextDirectoryEntry()) 46 | { 47 | printf("f: %s\n", d64ds.getFilename()); 48 | } 49 | 50 | logger.log("1234\n"); 51 | } -------------------------------------------------------------------------------- /legacy/src/avr/fsDataSource.cpp: -------------------------------------------------------------------------------- 1 | #include "fsDataSource.h" 2 | #include 3 | 4 | bool fsDataSource::init() 5 | { 6 | printf("fsDataSource init\n"); 7 | return true; 8 | } 9 | void fsDataSource::openFileForWriting(unsigned char* fileName) {} 10 | bool fsDataSource::openFileForReading(unsigned char* fileName) 11 | { 12 | printf("fsDataSource openFile %s\n", (char*)fileName); 13 | strcpy(_fileName, (const char*)fileName); 14 | printf("!\n"); 15 | _fp = fopen(_fileName, "rb+"); 16 | printf("@\n"); 17 | 18 | return true; 19 | } 20 | 21 | uint32_t fsDataSource::seek(unsigned int pos) 22 | { 23 | uint32_t q_pos = (pos / readBufferSize()) * readBufferSize(); 24 | printf("seek to %d, q %d\n", pos, q_pos); 25 | fseek(_fp, q_pos, SEEK_SET); 26 | return q_pos; 27 | } 28 | bool fsDataSource::openDirectory(const char* dirName) {} 29 | unsigned int fsDataSource::getNextFileBlock() 30 | { 31 | printf("reading at %d\n", ftell(_fp)); 32 | _bytesInBlock = (int)fread(_buffer, 1, readBufferSize(), _fp); 33 | 34 | return _bytesInBlock; 35 | } 36 | bool fsDataSource::isLastBlock() 37 | { 38 | return (_bytesInBlock < readBufferSize()); 39 | } 40 | bool fsDataSource::getNextDirectoryEntry() {} 41 | bool fsDataSource::isInitialized() {} 42 | 43 | void fsDataSource::writeBufferToFile(unsigned int numBytes) 44 | { 45 | printf("fs write to file %d\n", numBytes); 46 | fwrite(_buffer, 1, writeBufferSize(), _fp); 47 | } 48 | 49 | void fsDataSource::updateBlock() 50 | { 51 | printf("update block, writing at %d\n", ftell(_fp)); 52 | fwrite(_buffer, 1, writeBufferSize(), _fp); 53 | } 54 | 55 | void fsDataSource::closeFile() 56 | { 57 | 58 | } 59 | void fsDataSource::openCurrentDirectory() {} 60 | unsigned char* fsDataSource::getFilename() 61 | { 62 | return (unsigned char*)_fileName; 63 | } 64 | unsigned char* fsDataSource::getBuffer() 65 | { 66 | return _buffer; 67 | } 68 | unsigned int fsDataSource::writeBufferSize() 69 | { 70 | return 512; 71 | } -------------------------------------------------------------------------------- /legacy/src/avr/fsDataSource.h: -------------------------------------------------------------------------------- 1 | #ifndef __fs_datasource_h__ 2 | #define __fs_datasource_h__ 3 | 4 | #include 5 | #include "DataSource.h" 6 | 7 | class fsDataSource : public DataSource 8 | { 9 | public: 10 | fsDataSource() {} 11 | ~fsDataSource() {} 12 | 13 | bool init(); 14 | void openFileForWriting(unsigned char* fileName); 15 | bool openFileForReading(unsigned char* fileName); 16 | uint32_t seek(uint32_t pos); 17 | bool openDirectory(const char* dirName); 18 | unsigned int getNextFileBlock(); 19 | bool isLastBlock(); 20 | bool getNextDirectoryEntry(); 21 | bool isInitialized(); 22 | 23 | void writeBufferToFile(unsigned int numBytes); 24 | void updateBlock(); 25 | void closeFile(); 26 | void openCurrentDirectory(); 27 | unsigned char* getFilename(); 28 | unsigned char* getBuffer(); 29 | unsigned int writeBufferSize(); 30 | 31 | private: 32 | char _fileName[64]; 33 | unsigned char _buffer[512]; 34 | FILE* _fp; 35 | int _bytesInBlock; 36 | }; 37 | 38 | #endif -------------------------------------------------------------------------------- /legacy/src/avr/hardware_avr.cpp: -------------------------------------------------------------------------------- 1 | #include "../hardware.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #define ESP_CONTROL DDRD 12 | #define ESP_PORT PORTD 13 | #define ESP_CH_PD PD4 14 | #define ESP_RST PD5 15 | #define ESP_GPIO0 PD7 16 | #define ESP_GPIO2 PD6 17 | 18 | #define LED_CONTROL DDRB 19 | #define LED_PORT PORTB 20 | #define LED_PIN1 PB0 21 | #define LED_PIN2 PB1 22 | 23 | #define SPI_CONTROL DDRB 24 | #define SPI_PORT PORTB 25 | #define SPI_CS PB4 26 | #define SPI_CS2 PB3 27 | #define SPI_MOSI PB5 28 | #define SPI_SCK PB7 29 | 30 | #define SPI_CS_MASK 1<= 0.5f) 152 | { 153 | return i+1; 154 | } 155 | else 156 | { 157 | return i; 158 | } 159 | } 160 | 161 | uint8_t ubrrFromBaudRate(uint32_t baudRate, bool* doubleSpeed) 162 | { 163 | // try regular speed first 164 | float fRegUbrr = (float(F_CPU) / float(16*baudRate)) - 1.0f; 165 | uint32_t regUbrr = bRnd(fRegUbrr); 166 | // get real baud rate 167 | uint32_t actualRegBr = (float(F_CPU) / float(16*(regUbrr+1))); 168 | float regErr = 1.0 - (float)actualRegBr / (float)baudRate; 169 | if (regErr < 0.0) { 170 | regErr = -regErr; 171 | } 172 | 173 | // try double speed 174 | float fDblUbrr = (float(F_CPU) / float(8*baudRate)) - 1.0f; 175 | uint32_t dblUbrr = bRnd(fDblUbrr); 176 | // get real baud rate 177 | uint32_t actualDblBr = (F_CPU / (8*(dblUbrr+1))); 178 | float dblErr = 1.0 - (float)actualDblBr / (float)baudRate; 179 | if (dblErr < 0.0) { 180 | dblErr = -dblErr; 181 | } 182 | 183 | if (regErr <= dblErr) { 184 | *doubleSpeed = false; 185 | return (uint8_t)regUbrr; 186 | } else { 187 | *doubleSpeed = true; 188 | return (uint8_t)dblUbrr; 189 | } 190 | } 191 | 192 | void serial0_init(uint32_t baudRate) 193 | { 194 | bool double_speed; 195 | uint8_t ubrr = ubrrFromBaudRate(baudRate, &double_speed); 196 | 197 | UBRR0H = (unsigned char)(ubrr>>8); 198 | UBRR0L = (unsigned char)ubrr; 199 | UCSR0A = double_speed ? (1<>8); 234 | UBRR1L = (unsigned char)ubrr; 235 | UCSR1A = double_speed ? (1<deleteFile(); 270 | } 271 | 272 | bool isFirmwareFile(char* fname) 273 | { 274 | if (fname == NULL) 275 | { 276 | return false; 277 | } 278 | 279 | if (strlen(fname) != 12) 280 | { 281 | return false; 282 | } 283 | 284 | if (fname[0] == 'F' && 285 | fname[1] == 'I' && 286 | fname[2] == 'R' && 287 | fname[3] == 'M' && 288 | fname[9] == 'B' && 289 | fname[10] == 'I' && 290 | fname[11] == 'N') 291 | { 292 | return true; 293 | } 294 | 295 | return false; 296 | } -------------------------------------------------------------------------------- /legacy/src/avr/hardware_avr.h: -------------------------------------------------------------------------------- 1 | #ifndef __IEEE488_HARDWARE_H__ 2 | #define __IEEE488_HARDWARE_H__ 3 | 4 | #include 5 | #include 6 | 7 | #define IEEE_PORT PORTC 8 | #define IEEE_PIN PINC 9 | #define IEEE_CTL DDRC 10 | 11 | #define DATA_PORT PORTA 12 | #define DATA_PIN PINA 13 | #define DATA_CTL DDRA 14 | 15 | #define ATN_PIN PC0 16 | #define NDAC_PIN PC1 17 | #define DAV_PIN PC2 18 | #define NRFD_PIN PC3 19 | #define EOI_PIN PC4 20 | 21 | #define ATN_MASK 1< 6 | * 7 | * This software may be distributed under the terms of the BSD license. 8 | * See README for more details. 9 | */ 10 | 11 | // 2016-12-12 - Gaspard Petit : Slightly modified to return a std::string 12 | // instead of a buffer allocated with malloc. 13 | 14 | #include 15 | 16 | static const unsigned char base64_table[65] = 17 | "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; 18 | 19 | /** 20 | * base64_encode - Base64 encode 21 | * @src: Data to be encoded 22 | * @len: Length of the data to be encoded 23 | * @out_len: Pointer to output length variable, or %NULL if not used 24 | * Returns: Allocated buffer of out_len bytes of encoded data, 25 | * or empty string on failure 26 | */ 27 | std::string base64_encode(const unsigned char *src, size_t len) 28 | { 29 | unsigned char *out, *pos; 30 | const unsigned char *end, *in; 31 | 32 | size_t olen; 33 | 34 | olen = 4*((len + 2) / 3); /* 3-byte blocks to 4-byte */ 35 | 36 | if (olen < len) 37 | return std::string(); /* integer overflow */ 38 | 39 | std::string outStr; 40 | outStr.resize(olen); 41 | out = (unsigned char*)&outStr[0]; 42 | 43 | end = src + len; 44 | in = src; 45 | pos = out; 46 | while (end - in >= 3) { 47 | *pos++ = base64_table[in[0] >> 2]; 48 | *pos++ = base64_table[((in[0] & 0x03) << 4) | (in[1] >> 4)]; 49 | *pos++ = base64_table[((in[1] & 0x0f) << 2) | (in[2] >> 6)]; 50 | *pos++ = base64_table[in[2] & 0x3f]; 51 | in += 3; 52 | } 53 | 54 | if (end - in) { 55 | *pos++ = base64_table[in[0] >> 2]; 56 | if (end - in == 1) { 57 | *pos++ = base64_table[(in[0] & 0x03) << 4]; 58 | *pos++ = '='; 59 | } 60 | else { 61 | *pos++ = base64_table[((in[0] & 0x03) << 4) | 62 | (in[1] >> 4)]; 63 | *pos++ = base64_table[(in[1] & 0x0f) << 2]; 64 | } 65 | *pos++ = '='; 66 | } 67 | 68 | return outStr; 69 | } -------------------------------------------------------------------------------- /legacy/src/base64.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | -------------------------------------------------------------------------------- /legacy/src/cbmlayout.h: -------------------------------------------------------------------------------- 1 | unsigned char LAYOUT_CBM[] = { 2 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x15, 0x00, 0x00, 0x00, 0x2a, 0x00, 0x00, 3 | 0x00, 0x3f, 0x00, 0x00, 0x00, 0x54, 0x00, 0x00, 0x00, 0x69, 0x00, 0x00, 4 | 0x00, 0x7e, 0x00, 0x00, 0x00, 0x93, 0x00, 0x00, 0x00, 0xa8, 0x00, 0x00, 5 | 0x00, 0xbd, 0x00, 0x00, 0x00, 0xd2, 0x00, 0x00, 0x00, 0xe7, 0x00, 0x00, 6 | 0x00, 0xfc, 0x00, 0x00, 0x00, 0x11, 0x01, 0x00, 0x00, 0x26, 0x01, 0x00, 7 | 0x00, 0x3b, 0x01, 0x00, 0x00, 0x50, 0x01, 0x00, 0x00, 0x65, 0x01, 0x00, 8 | 0x00, 0x78, 0x01, 0x00, 0x00, 0x8b, 0x01, 0x00, 0x00, 0x9e, 0x01, 0x00, 9 | 0x00, 0xb1, 0x01, 0x00, 0x00, 0xc4, 0x01, 0x00, 0x00, 0xd7, 0x01, 0x00, 10 | 0x00, 0xea, 0x01, 0x00, 0x00, 0xfc, 0x01, 0x00, 0x00, 0x0e, 0x02, 0x00, 11 | 0x00, 0x20, 0x02, 0x00, 0x00, 0x32, 0x02, 0x00, 0x00, 0x44, 0x02, 0x00, 12 | 0x00, 0x56, 0x02, 0x00, 0x00, 0x67, 0x02, 0x00, 0x00, 0x78, 0x02, 0x00, 13 | 0x00, 0x89, 0x02, 0x00, 0x00, 0x9a, 0x02, 0x00, 0x00, 0xab, 0x02, 0x00, 14 | 0x00, 0xbc, 0x02, 0x00, 0x00, 0xcd, 0x02, 0x00, 0x00, 0xde, 0x02, 0x00, 15 | 0x00, 0xef, 0x02, 0x00, 0x00, 0x00, 0x03, 0x00 16 | }; 17 | unsigned int LAYOUT_CBM_len = 164; 18 | -------------------------------------------------------------------------------- /legacy/src/esp32/EspConn.cpp: -------------------------------------------------------------------------------- 1 | #include "EspConn.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | namespace bitfixer 10 | { 11 | 12 | WiFiClient client; 13 | HTTPClient httpClient; 14 | 15 | bool EspConn::device_present() { 16 | // always present for esp32 device 17 | return true; 18 | } 19 | 20 | bool EspConn::attempt_baud_rate_setting() { 21 | // not applicable 22 | return true; 23 | } 24 | 25 | bool EspConn::initWithParams(uint8_t* buffer, uint16_t* bufferSize, Serial* serial, Logger* logSerial) 26 | { 27 | _serialBuffer = buffer; 28 | _serialBufferSize = bufferSize; 29 | _serial = serial; 30 | _logSerial = logSerial; 31 | init(); 32 | return true; 33 | } 34 | 35 | bool EspConn::init() { 36 | // not applicable 37 | return true; 38 | } 39 | 40 | void EspConn::scanNetworks() { 41 | int n = WiFi.scanNetworks(); 42 | _logSerial->printf("found %d networks.\n", n); 43 | for (int i = 0; i < n; i++) 44 | { 45 | _logSerial->printf("%d: %s %d\n", i, WiFi.SSID(i).c_str(), WiFi.RSSI(i)); 46 | } 47 | } 48 | 49 | void EspConn::setDns() { 50 | // not applicable 51 | } 52 | 53 | void EspConn::copyEscapedString(char* dest, const char* src) 54 | { 55 | int srcLen = strlen(src); 56 | char* destptr = dest; 57 | 58 | for (int i = 0; i < srcLen; i++) 59 | { 60 | char c = src[i]; 61 | if (isalnum(c)) 62 | { 63 | *destptr++ = c; 64 | } 65 | else 66 | { 67 | sprintf(destptr, "\\%c", c); 68 | destptr += 2; 69 | } 70 | } 71 | destptr = 0x00; 72 | } 73 | 74 | bool EspConn::connect(const char* ssid, const char* passphrase) { 75 | WiFi.begin(ssid, passphrase); 76 | while (WiFi.status() != WL_CONNECTED) { 77 | delay(500); 78 | _logSerial->printf("."); 79 | } 80 | _logSerial->printf("wifi connected\n"); 81 | return true; 82 | // todo: handle connection failure 83 | } 84 | 85 | bool EspConn::sendCmd(const char* cmd, int timeout) { 86 | return true; 87 | } 88 | 89 | bool EspConn::startClient(const char* host, uint16_t port, uint8_t sock, uint8_t protMode) 90 | { 91 | int ret = client.connect(host, port); 92 | if (ret == 1) 93 | { 94 | return true; 95 | } 96 | 97 | return false; 98 | } 99 | 100 | void EspConn::stopClient(uint8_t sock) 101 | { 102 | } 103 | 104 | int contains(const char* big, const char* small, size_t size) 105 | { 106 | int sm_len = strlen(small); 107 | int end = size - sm_len; 108 | for (int i = 0; i <= end; i++) 109 | { 110 | if (big[i] == small[0]) 111 | { 112 | if (memcmp(&big[i], small, sm_len) == 0) 113 | { 114 | return i; 115 | } 116 | } 117 | } 118 | 119 | return -1; 120 | } 121 | 122 | void EspConn::sendData(uint8_t sock, unsigned char* data, int len) 123 | { 124 | client.write(data, len); 125 | int recCount = 0; 126 | while (client.available() || client.connected()) 127 | { 128 | int byte = client.read(); 129 | if (byte != -1) 130 | { 131 | // guard against buffer overflow 132 | if (recCount < 1000) { 133 | _serialBuffer[recCount] = byte; 134 | recCount++; 135 | _logSerial->log((unsigned char*)&byte, 1); 136 | } 137 | } 138 | } 139 | 140 | *_serialBufferSize = recCount; 141 | } 142 | 143 | void EspConn::readBytesUntilSize(uint16_t size) 144 | { 145 | } 146 | 147 | bool endsWith(const char* big, const char* small, size_t size) 148 | { 149 | int start = size - strlen(small); 150 | for (int i = 0; i < (int)strlen(small); i++) 151 | { 152 | if (big[i+start] != small[i]) 153 | { 154 | return false; 155 | } 156 | } 157 | 158 | return true; 159 | } 160 | 161 | int EspConn::readUntil(const char* tag, bool findTags, bool end, int timeout) { 162 | return -1; 163 | } 164 | 165 | void EspConn::reset() { 166 | } 167 | 168 | } -------------------------------------------------------------------------------- /legacy/src/esp32/hardware_esp32.cpp: -------------------------------------------------------------------------------- 1 | #include "hardware.h" 2 | #include 3 | #include 4 | #include 5 | 6 | #define LED_PIN 2 7 | #define CS_PIN 4 8 | 9 | uint8_t spi_cs() 10 | { 11 | return CS_PIN; 12 | } 13 | 14 | void prog_init() 15 | { 16 | // nothing for esp32 17 | set_atn_input(); 18 | EEPROM.begin(512); 19 | } 20 | 21 | void reset_esp() 22 | { 23 | // nothing for esp32 24 | } 25 | 26 | void init_led() 27 | { 28 | // nothing for esp32 29 | pinMode(LED_PIN, OUTPUT); 30 | } 31 | 32 | void set_led(bool value) 33 | { 34 | if (value == true) 35 | { 36 | digitalWrite(LED_PIN, HIGH); 37 | } 38 | else 39 | { 40 | digitalWrite(LED_PIN, LOW); 41 | } 42 | } 43 | 44 | void hDelayMs(int ms) 45 | { 46 | delay(ms); 47 | } 48 | 49 | uint8_t bf_pgm_read_byte(uint8_t* src) 50 | { 51 | return pgm_read_byte(src); 52 | } 53 | 54 | void bf_eeprom_write_block(const void* block, void* eeprom, size_t n) 55 | { 56 | EEPROM.writeBytes((int)eeprom, block, n); 57 | EEPROM.commit(); 58 | } 59 | 60 | void bf_eeprom_read_block(void* block, const void* eeprom, size_t n) 61 | { 62 | EEPROM.readBytes((int)eeprom, (void*)block, n); 63 | } 64 | 65 | uint8_t bf_eeprom_read_byte(const uint8_t* addr) 66 | { 67 | return EEPROM.readByte((int)addr); 68 | } 69 | 70 | // SPI 71 | 72 | void spi_init() 73 | { 74 | pinMode(CS_PIN, OUTPUT); 75 | spi_cs_unselect(); 76 | SPI.begin(); 77 | } 78 | 79 | uint8_t spi_transmit(uint8_t data) 80 | { 81 | return SPI.transfer(data); 82 | } 83 | 84 | void spi_cs_select() 85 | { 86 | digitalWrite(CS_PIN, LOW); 87 | } 88 | 89 | void spi_cs_unselect() 90 | { 91 | digitalWrite(CS_PIN, 1); 92 | } 93 | 94 | // serial 95 | 96 | void serial0_init(uint32_t baudRate) 97 | { 98 | // N/A 99 | } 100 | 101 | void serial0_transmitByte(unsigned char data) 102 | { 103 | // N/A 104 | } 105 | 106 | unsigned char serial0_receiveByte() 107 | { 108 | return 0; 109 | } 110 | 111 | void serial0_enable_interrupt() 112 | { 113 | // N/A 114 | } 115 | 116 | void serial0_disable_interrupt() 117 | { 118 | // N/A 119 | } 120 | 121 | void serial1_init(uint32_t baudRate) 122 | { 123 | ::Serial.begin(baudRate); 124 | } 125 | 126 | void serial1_transmitByte(unsigned char data) 127 | { 128 | ::Serial.write(data); 129 | } 130 | 131 | unsigned char serial1_receiveByte() 132 | { 133 | int ret = ::Serial.read(); 134 | while (ret == -1) 135 | { 136 | ret = ::Serial.read(); 137 | } 138 | 139 | return (unsigned char)ret; 140 | } 141 | 142 | void serial1_enable_interrupt() 143 | { 144 | // N/A 145 | } 146 | 147 | void serial1_disable_interrupt() 148 | { 149 | // N/A 150 | } 151 | 152 | bool isFirmwareFile(char* fname) 153 | { 154 | if (fname == NULL) 155 | { 156 | return false; 157 | } 158 | 159 | if (strlen(fname) != 12) 160 | { 161 | return false; 162 | } 163 | 164 | if (fname[0] == 'F' && 165 | fname[1] == 'I' && 166 | fname[2] == 'R' && 167 | fname[3] == 'M' && 168 | fname[9] == 'P' && 169 | fname[10] == 'D' && 170 | fname[11] == '2') 171 | { 172 | return true; 173 | } 174 | 175 | return false; 176 | } -------------------------------------------------------------------------------- /legacy/src/esp32/hardware_esp32.h: -------------------------------------------------------------------------------- 1 | #ifndef __hardware_esp32_h__ 2 | #define __hardware_esp32_h__ 3 | 4 | #include 5 | #include 6 | #define sscanf_P sscanf 7 | 8 | #define DATA0 32 9 | #define DATA1 33 10 | #define DATA2 25 11 | #define DATA3 26 12 | #define DATA4 27 13 | #define DATA5 14 14 | #define DATA6 12 15 | #define DATA7 13 16 | 17 | #define DATADIR 15 18 | 19 | #define ATN_PIN 5 20 | #define EOI_PIN 22 21 | #define DAV_PIN 21 22 | #define NRFD_PIN 17 23 | #define NDAC_PIN 16 24 | 25 | #define lower_eoi() digitalWrite(EOI_PIN, LOW) 26 | #define lower_dav() digitalWrite(DAV_PIN, LOW) 27 | #define lower_nrfd() digitalWrite(NRFD_PIN, LOW) 28 | #define lower_ndac() digitalWrite(NDAC_PIN, LOW) 29 | 30 | #define raise_eoi() digitalWrite(EOI_PIN, HIGH) 31 | #define raise_dav() digitalWrite(DAV_PIN, HIGH) 32 | #define raise_nrfd() digitalWrite(NRFD_PIN, HIGH) 33 | #define raise_ndac() digitalWrite(NDAC_PIN, HIGH) 34 | 35 | #define read_atn() digitalRead(ATN_PIN) 36 | #define read_eoi() digitalRead(EOI_PIN) 37 | #define read_dav() digitalRead(DAV_PIN) 38 | #define read_nrfd() digitalRead(NRFD_PIN) 39 | #define read_ndac() digitalRead(NDAC_PIN) 40 | 41 | #define set_atn_input() pinMode(ATN_PIN, INPUT_PULLUP) 42 | #define set_eoi_input() pinMode(EOI_PIN, INPUT_PULLUP) 43 | #define set_dav_input() pinMode(DAV_PIN, INPUT_PULLUP) 44 | #define set_nrfd_input() pinMode(NRFD_PIN, INPUT_PULLUP) 45 | #define set_ndac_input() pinMode(NDAC_PIN, INPUT_PULLUP) 46 | 47 | #define set_eoi_output() pinMode(EOI_PIN, OUTPUT) 48 | #define set_dav_output() pinMode(DAV_PIN, OUTPUT) 49 | #define set_nrfd_output() pinMode(NRFD_PIN, OUTPUT) 50 | #define set_ndac_output() pinMode(NDAC_PIN, OUTPUT) 51 | #define set_datadir_output() pinMode(DATADIR, OUTPUT) 52 | 53 | #define ieee_read_data_byte(recvByte) ({\ 54 | recvByte += digitalRead(DATA7); recvByte <<= 1;\ 55 | recvByte += digitalRead(DATA6); recvByte <<= 1;\ 56 | recvByte += digitalRead(DATA5); recvByte <<= 1;\ 57 | recvByte += digitalRead(DATA4); recvByte <<= 1;\ 58 | recvByte += digitalRead(DATA3); recvByte <<= 1;\ 59 | recvByte += digitalRead(DATA2); recvByte <<= 1;\ 60 | recvByte += digitalRead(DATA1); recvByte <<= 1;\ 61 | recvByte += digitalRead(DATA0);\ 62 | }) 63 | 64 | #define ieee_write_data_byte(byte) ({\ 65 | digitalWrite(DATA0, byte & 0x01); byte >>= 1;\ 66 | digitalWrite(DATA1, byte & 0x01); byte >>= 1;\ 67 | digitalWrite(DATA2, byte & 0x01); byte >>= 1;\ 68 | digitalWrite(DATA3, byte & 0x01); byte >>= 1;\ 69 | digitalWrite(DATA4, byte & 0x01); byte >>= 1;\ 70 | digitalWrite(DATA5, byte & 0x01); byte >>= 1;\ 71 | digitalWrite(DATA6, byte & 0x01); byte >>= 1;\ 72 | digitalWrite(DATA7, byte & 0x01);\ 73 | }) 74 | 75 | #define ieee_set_data_output() ({\ 76 | digitalWrite(DATADIR, HIGH);\ 77 | pinMode(DATA0, OUTPUT);\ 78 | pinMode(DATA1, OUTPUT);\ 79 | pinMode(DATA2, OUTPUT);\ 80 | pinMode(DATA3, OUTPUT);\ 81 | pinMode(DATA4, OUTPUT);\ 82 | pinMode(DATA5, OUTPUT);\ 83 | pinMode(DATA6, OUTPUT);\ 84 | pinMode(DATA7, OUTPUT);\ 85 | }) 86 | 87 | #define ieee_set_data_input() ({\ 88 | pinMode(DATA0, INPUT_PULLUP);\ 89 | pinMode(DATA1, INPUT_PULLUP);\ 90 | pinMode(DATA2, INPUT_PULLUP);\ 91 | pinMode(DATA3, INPUT_PULLUP);\ 92 | pinMode(DATA4, INPUT_PULLUP);\ 93 | pinMode(DATA5, INPUT_PULLUP);\ 94 | pinMode(DATA6, INPUT_PULLUP);\ 95 | pinMode(DATA7, INPUT_PULLUP);\ 96 | digitalWrite(DATADIR, LOW);\ 97 | }) 98 | 99 | #endif -------------------------------------------------------------------------------- /legacy/src/hardware.h: -------------------------------------------------------------------------------- 1 | #ifndef __hardware_h__ 2 | #define __hardware_h__ 3 | 4 | #ifdef ISAVR 5 | #include "hardware_avr.h" 6 | #else 7 | #include "hardware_esp32.h" 8 | #endif 9 | 10 | #include 11 | #include 12 | #include "FAT32.h" 13 | #include "Logger.h" 14 | 15 | #define PACKED __attribute__ ((packed)) 16 | 17 | uint8_t spi_cs(); 18 | void prog_init(); 19 | void reset_esp(); 20 | void init_led(); 21 | void set_led(bool value); 22 | void hDelayMs(int ms); 23 | uint8_t bf_pgm_read_byte(uint8_t* src); 24 | 25 | void bf_eeprom_write_block(const void* block, void* eeprom, size_t n); 26 | void bf_eeprom_read_block(void* block, const void* eeprom, size_t n); 27 | uint8_t bf_eeprom_read_byte(const uint8_t* addr); 28 | 29 | void spi_init(); 30 | uint8_t spi_transmit(uint8_t data); 31 | void spi_cs_select(); 32 | void spi_cs_unselect(); 33 | 34 | void serial0_init(uint32_t baudRate); 35 | void serial0_transmitByte(unsigned char data); 36 | unsigned char serial0_receiveByte(); 37 | void serial0_enable_interrupt(); 38 | void serial0_disable_interrupt(); 39 | 40 | void serial1_init(uint32_t baudRate); 41 | void serial1_transmitByte(unsigned char data); 42 | unsigned char serial1_receiveByte(); 43 | void serial1_enable_interrupt(); 44 | void serial1_disable_interrupt(); 45 | 46 | bool isFirmwareFile(char* fname); 47 | 48 | #endif -------------------------------------------------------------------------------- /legacy/src/helpers.cpp: -------------------------------------------------------------------------------- 1 | #include "helpers.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | const void *bf_memmem(const void *haystack, size_t haystacklen, const void *needle, size_t needlelen) 8 | { 9 | uint8_t* hh = (uint8_t*)haystack; 10 | uint8_t* nn = (uint8_t*)needle; 11 | 12 | //uint32_t bytesToCheck = haystacklen - needlelen - 1; 13 | int last = haystacklen - needlelen + 1; 14 | for (int i = 0; i < last; i++) 15 | { 16 | if (hh[i] == nn[0]) 17 | { 18 | // compare bytes of haystack and needle 19 | if (memcmp(&hh[i], nn, needlelen) == 0) 20 | { 21 | return &hh[i]; 22 | } 23 | } 24 | } 25 | 26 | return NULL; 27 | } 28 | 29 | void lowerStringInPlace(char* str) 30 | { 31 | char* c = str; 32 | while (*c != 0) 33 | { 34 | *c = tolower(*c); 35 | c++; 36 | } 37 | } 38 | 39 | void upperStringInPlace(char* str) 40 | { 41 | char* c = str; 42 | while (*c != 0) 43 | { 44 | *c = toupper(*c); 45 | c++; 46 | } 47 | } -------------------------------------------------------------------------------- /legacy/src/helpers.h: -------------------------------------------------------------------------------- 1 | #ifndef __helpers_h__ 2 | #define __helpers_h__ 3 | 4 | #include 5 | #define PACKED __attribute__ ((packed)) 6 | 7 | const void *bf_memmem( 8 | const void *haystack, size_t haystacklen, 9 | const void *needle, size_t needlelen ); 10 | 11 | void lowerStringInPlace(char* str); 12 | void upperStringInPlace(char* str); 13 | 14 | #endif -------------------------------------------------------------------------------- /legacy/src/tools/filesize.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(int argc, char** argv) { 4 | if (argc != 2) 5 | { 6 | return 1; 7 | } 8 | 9 | FILE* fp = fopen(argv[1], "rb"); 10 | fseek(fp, 0, SEEK_END); 11 | int size = ftell(fp); 12 | fclose(fp); 13 | 14 | printf("%d", size); 15 | } -------------------------------------------------------------------------------- /schematics/PETdisk_MAX_Schematic.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bitfixer/petdisk-max/7ca0859926249b7c8f7e129c2beb325d5b22a573/schematics/PETdisk_MAX_Schematic.pdf -------------------------------------------------------------------------------- /schematics/dip_version/gerbers/petdisk_max_dip_bottom_paste.gbp: -------------------------------------------------------------------------------- 1 | G04 EAGLE Gerber RS-274X export* 2 | G75* 3 | %MOMM*% 4 | %FSLAX34Y34*% 5 | %LPD*% 6 | %INBottom Solder Paste*% 7 | %IPPOS*% 8 | %AMOC8* 9 | 5,1,8,0,0,1.08239X$1,22.5*% 10 | G01* 11 | %ADD10C,0.762000*% 12 | %ADD11R,1.350000X1.500000*% 13 | %ADD12R,1.500000X1.300000*% 14 | %ADD13R,1.600000X0.500000*% 15 | %ADD14R,1.400000X1.000000*% 16 | %ADD15R,1.500000X1.500000*% 17 | %ADD16C,0.300000*% 18 | %ADD17R,0.950000X1.250000*% 19 | %ADD18R,3.200000X1.250000*% 20 | %ADD19R,1.800000X1.600000*% 21 | %ADD20R,1.000000X1.100000*% 22 | %ADD21R,1.100000X1.000000*% 23 | %ADD22R,1.905000X8.255000*% 24 | 25 | 26 | D10* 27 | X577498Y49690D02* 28 | X595278Y49690D01* 29 | X595278Y6510D01* 30 | X577498Y6510D01* 31 | X577498Y49690D01* 32 | X577498Y13749D02* 33 | X595278Y13749D01* 34 | X595278Y20988D02* 35 | X577498Y20988D01* 36 | X577498Y28227D02* 37 | X595278Y28227D01* 38 | X595278Y35466D02* 39 | X577498Y35466D01* 40 | X577498Y42705D02* 41 | X595278Y42705D01* 42 | X555678Y49690D02* 43 | X537898Y49690D01* 44 | X555678Y49690D02* 45 | X555678Y6510D01* 46 | X537898Y6510D01* 47 | X537898Y49690D01* 48 | X537898Y13749D02* 49 | X555678Y13749D01* 50 | X555678Y20988D02* 51 | X537898Y20988D01* 52 | X537898Y28227D02* 53 | X555678Y28227D01* 54 | X555678Y35466D02* 55 | X537898Y35466D01* 56 | X537898Y42705D02* 57 | X555678Y42705D01* 58 | X516078Y49690D02* 59 | X498298Y49690D01* 60 | X516078Y49690D02* 61 | X516078Y6510D01* 62 | X498298Y6510D01* 63 | X498298Y49690D01* 64 | X498298Y13749D02* 65 | X516078Y13749D01* 66 | X516078Y20988D02* 67 | X498298Y20988D01* 68 | X498298Y28227D02* 69 | X516078Y28227D01* 70 | X516078Y35466D02* 71 | X498298Y35466D01* 72 | X498298Y42705D02* 73 | X516078Y42705D01* 74 | X476478Y49690D02* 75 | X458698Y49690D01* 76 | X476478Y49690D02* 77 | X476478Y6510D01* 78 | X458698Y6510D01* 79 | X458698Y49690D01* 80 | X458698Y13749D02* 81 | X476478Y13749D01* 82 | X476478Y20988D02* 83 | X458698Y20988D01* 84 | X458698Y28227D02* 85 | X476478Y28227D01* 86 | X476478Y35466D02* 87 | X458698Y35466D01* 88 | X458698Y42705D02* 89 | X476478Y42705D01* 90 | X436878Y49690D02* 91 | X419098Y49690D01* 92 | X436878Y49690D02* 93 | X436878Y6510D01* 94 | X419098Y6510D01* 95 | X419098Y49690D01* 96 | X419098Y13749D02* 97 | X436878Y13749D01* 98 | X436878Y20988D02* 99 | X419098Y20988D01* 100 | X419098Y28227D02* 101 | X436878Y28227D01* 102 | X436878Y35466D02* 103 | X419098Y35466D01* 104 | X419098Y42705D02* 105 | X436878Y42705D01* 106 | X397278Y49690D02* 107 | X379498Y49690D01* 108 | X397278Y49690D02* 109 | X397278Y6510D01* 110 | X379498Y6510D01* 111 | X379498Y49690D01* 112 | X379498Y13749D02* 113 | X397278Y13749D01* 114 | X397278Y20988D02* 115 | X379498Y20988D01* 116 | X379498Y28227D02* 117 | X397278Y28227D01* 118 | X397278Y35466D02* 119 | X379498Y35466D01* 120 | X379498Y42705D02* 121 | X397278Y42705D01* 122 | X357678Y49690D02* 123 | X339898Y49690D01* 124 | X357678Y49690D02* 125 | X357678Y6510D01* 126 | X339898Y6510D01* 127 | X339898Y49690D01* 128 | X339898Y13749D02* 129 | X357678Y13749D01* 130 | X357678Y20988D02* 131 | X339898Y20988D01* 132 | X339898Y28227D02* 133 | X357678Y28227D01* 134 | X357678Y35466D02* 135 | X339898Y35466D01* 136 | X339898Y42705D02* 137 | X357678Y42705D01* 138 | X318078Y49690D02* 139 | X300298Y49690D01* 140 | X318078Y49690D02* 141 | X318078Y6510D01* 142 | X300298Y6510D01* 143 | X300298Y49690D01* 144 | X300298Y13749D02* 145 | X318078Y13749D01* 146 | X318078Y20988D02* 147 | X300298Y20988D01* 148 | X300298Y28227D02* 149 | X318078Y28227D01* 150 | X318078Y35466D02* 151 | X300298Y35466D01* 152 | X300298Y42705D02* 153 | X318078Y42705D01* 154 | X278478Y49690D02* 155 | X260698Y49690D01* 156 | X278478Y49690D02* 157 | X278478Y6510D01* 158 | X260698Y6510D01* 159 | X260698Y49690D01* 160 | X260698Y13749D02* 161 | X278478Y13749D01* 162 | X278478Y20988D02* 163 | X260698Y20988D01* 164 | X260698Y28227D02* 165 | X278478Y28227D01* 166 | X278478Y35466D02* 167 | X260698Y35466D01* 168 | X260698Y42705D02* 169 | X278478Y42705D01* 170 | X238878Y49690D02* 171 | X221098Y49690D01* 172 | X238878Y49690D02* 173 | X238878Y6510D01* 174 | X221098Y6510D01* 175 | X221098Y49690D01* 176 | X221098Y13749D02* 177 | X238878Y13749D01* 178 | X238878Y20988D02* 179 | X221098Y20988D01* 180 | X221098Y28227D02* 181 | X238878Y28227D01* 182 | X238878Y35466D02* 183 | X221098Y35466D01* 184 | X221098Y42705D02* 185 | X238878Y42705D01* 186 | X199278Y49690D02* 187 | X181498Y49690D01* 188 | X199278Y49690D02* 189 | X199278Y6510D01* 190 | X181498Y6510D01* 191 | X181498Y49690D01* 192 | X181498Y13749D02* 193 | X199278Y13749D01* 194 | X199278Y20988D02* 195 | X181498Y20988D01* 196 | X181498Y28227D02* 197 | X199278Y28227D01* 198 | X199278Y35466D02* 199 | X181498Y35466D01* 200 | X181498Y42705D02* 201 | X199278Y42705D01* 202 | X159678Y49690D02* 203 | X141898Y49690D01* 204 | X159678Y49690D02* 205 | X159678Y6510D01* 206 | X141898Y6510D01* 207 | X141898Y49690D01* 208 | X141898Y13749D02* 209 | X159678Y13749D01* 210 | X159678Y20988D02* 211 | X141898Y20988D01* 212 | X141898Y28227D02* 213 | X159678Y28227D01* 214 | X159678Y35466D02* 215 | X141898Y35466D01* 216 | X141898Y42705D02* 217 | X159678Y42705D01* 218 | D11* 219 | X21500Y96000D03* 220 | D12* 221 | X21500Y254000D03* 222 | D13* 223 | X123000Y109000D03* 224 | X123000Y120000D03* 225 | X123000Y131000D03* 226 | X123000Y142000D03* 227 | X123000Y153000D03* 228 | X123000Y164000D03* 229 | X123000Y175000D03* 230 | X123000Y186000D03* 231 | X123000Y197000D03* 232 | D14* 233 | X117500Y96000D03* 234 | D15* 235 | X117500Y240000D03* 236 | D16* 237 | X597730Y261500D02* 238 | X597730Y268500D01* 239 | X604730Y268500D01* 240 | X604730Y261500D01* 241 | X597730Y261500D01* 242 | X597730Y264350D02* 243 | X604730Y264350D01* 244 | X604730Y267200D02* 245 | X597730Y267200D01* 246 | X615270Y268500D02* 247 | X615270Y261500D01* 248 | X615270Y268500D02* 249 | X622270Y268500D01* 250 | X622270Y261500D01* 251 | X615270Y261500D01* 252 | X615270Y264350D02* 253 | X622270Y264350D01* 254 | X622270Y267200D02* 255 | X615270Y267200D01* 256 | X562730Y268500D02* 257 | X562730Y261500D01* 258 | X562730Y268500D02* 259 | X569730Y268500D01* 260 | X569730Y261500D01* 261 | X562730Y261500D01* 262 | X562730Y264350D02* 263 | X569730Y264350D01* 264 | X569730Y267200D02* 265 | X562730Y267200D01* 266 | X580270Y268500D02* 267 | X580270Y261500D01* 268 | X580270Y268500D02* 269 | X587270Y268500D01* 270 | X587270Y261500D01* 271 | X580270Y261500D01* 272 | X580270Y264350D02* 273 | X587270Y264350D01* 274 | X587270Y267200D02* 275 | X580270Y267200D01* 276 | D17* 277 | X652000Y209000D03* 278 | X675000Y209000D03* 279 | X698000Y209000D03* 280 | D18* 281 | X675000Y141000D03* 282 | D19* 283 | X725000Y161000D03* 284 | X725000Y189000D03* 285 | X625000Y189000D03* 286 | X625000Y161000D03* 287 | D20* 288 | X393000Y198500D03* 289 | X393000Y215500D03* 290 | X260000Y174500D03* 291 | X260000Y191500D03* 292 | D21* 293 | X414500Y215000D03* 294 | X431500Y215000D03* 295 | X531500Y265000D03* 296 | X548500Y265000D03* 297 | X496500Y265000D03* 298 | X513500Y265000D03* 299 | D19* 300 | X162000Y171000D03* 301 | X162000Y199000D03* 302 | D20* 303 | X185500Y171000D03* 304 | X185500Y188000D03* 305 | D19* 306 | X239000Y171000D03* 307 | X239000Y199000D03* 308 | X600000Y189000D03* 309 | X600000Y161000D03* 310 | D22* 311 | X589800Y330540D03* 312 | X550200Y330540D03* 313 | X510600Y330540D03* 314 | X471000Y330540D03* 315 | X431400Y330540D03* 316 | X391800Y330540D03* 317 | X352200Y330540D03* 318 | X312600Y330540D03* 319 | X273000Y330540D03* 320 | X233400Y330540D03* 321 | X193800Y330540D03* 322 | X154200Y330540D03* 323 | M02* 324 | -------------------------------------------------------------------------------- /schematics/dip_version/gerbers/petdisk_max_dip_drills.txt: -------------------------------------------------------------------------------- 1 | M48 2 | ;GenerationSoftware,Autodesk,EAGLE,9.6.1*% 3 | ;CreationDate,2022-01-26T19:57:01Z*% 4 | FMAT,2 5 | ICI,OFF 6 | METRIC,TZ,000.000 7 | T4C0.350 8 | T3C0.784 9 | T2C0.800 10 | T1C1.016 11 | % 12 | G90 13 | M71 14 | T1 15 | X7540Y3730 16 | X7540Y6270 17 | X5000Y3730 18 | X5000Y6270 19 | X2460Y3730 20 | X2460Y6270 21 | X72310Y3900 22 | X69770Y3900 23 | X72310Y6440 24 | X69770Y6440 25 | X72310Y8980 26 | X69770Y8980 27 | T2 28 | X28962Y20395 29 | X28962Y12775 30 | X28962Y15315 31 | X28962Y17855 32 | X31502Y17855 33 | X31502Y15315 34 | X31502Y20395 35 | X31502Y12775 36 | T3 37 | X62800Y8965 38 | X60260Y8965 39 | X57720Y8965 40 | X55180Y8965 41 | X52640Y8965 42 | X50100Y8965 43 | X47560Y8965 44 | X45020Y8965 45 | X42480Y8965 46 | X39940Y8965 47 | X37400Y8965 48 | X34860Y8965 49 | X32320Y8965 50 | X29780Y8965 51 | X27240Y8965 52 | X24700Y8965 53 | X22160Y8965 54 | X19620Y8965 55 | X17080Y8965 56 | X14540Y8965 57 | X14540Y24395 58 | X17080Y24395 59 | X19620Y24395 60 | X22160Y24395 61 | X24700Y24395 62 | X27240Y24395 63 | X29780Y24395 64 | X32320Y24395 65 | X34860Y24395 66 | X37400Y24395 67 | X39940Y24395 68 | X42480Y24395 69 | X45020Y24395 70 | X47560Y24395 71 | X50100Y24395 72 | X52640Y24395 73 | X55180Y24395 74 | X57720Y24395 75 | X60260Y24395 76 | X62800Y24395 77 | T4 78 | X48500Y6250 79 | X53750Y6500 80 | X45250Y6500 81 | X10500Y11750 82 | X11000Y16250 83 | X10250Y17500 84 | X36250Y10750 85 | X42250Y25500 86 | X5000Y12000 87 | X47500Y17750 88 | X9500Y15250 89 | X45000Y17750 90 | X52750Y5000 91 | X56750Y5750 92 | X25000Y5000 93 | X29000Y5500 94 | X32750Y5750 95 | X36750Y6250 96 | X41000Y6500 97 | X14000Y27000 98 | X24000Y7500 99 | X55300Y10400 100 | X57500Y7500 101 | X57500Y11500 102 | X55000Y17000 103 | X57500Y17000 104 | X57500Y22000 105 | X55000Y22000 106 | X51500Y22000 107 | X51500Y17000 108 | X51500Y13500 109 | X47500Y13500 110 | X46000Y13500 111 | X46000Y17500 112 | X46000Y22000 113 | X45500Y27000 114 | X23500Y14000 115 | X26000Y14000 116 | X20000Y16000 117 | X22500Y15500 118 | X20500Y19500 119 | X22500Y19500 120 | X26000Y21500 121 | X26000Y23500 122 | X33500Y22000 123 | X37500Y22000 124 | X37500Y18500 125 | X41000Y18500 126 | X41000Y27000 127 | X37500Y27000 128 | X33500Y27000 129 | X29500Y27000 130 | X25000Y27000 131 | X20000Y27000 132 | X43250Y26750 133 | X44000Y12500 134 | X47250Y26750 135 | X48750Y17750 136 | X48500Y26750 137 | X49750Y17750 138 | X60000Y27404 139 | X63500Y14000 140 | X62250Y28000 141 | X64500Y14000 142 | X23400Y24900 143 | X22400Y21500 144 | X21200Y16400 145 | X21200Y14900 146 | X26900Y5954 147 | X21600Y10900 148 | X26250Y10000 149 | X40250Y25500 150 | M30 -------------------------------------------------------------------------------- /schematics/dip_version/gerbers/petdisk_max_dip_drills_NPTH.txt: -------------------------------------------------------------------------------- 1 | M48 2 | ;GenerationSoftware,Autodesk,EAGLE,9.6.1*% 3 | ;CreationDate,2022-01-26T19:57:01Z*% 4 | FMAT,2 5 | ICI,OFF 6 | METRIC,TZ,000.000 7 | T2C0.350 8 | T1C0.800 9 | % 10 | G90 11 | M71 12 | T1 13 | X1750Y12550 14 | X1750Y20550 15 | T2 16 | X57500Y26500 17 | X61000Y26500 18 | M30 -------------------------------------------------------------------------------- /schematics/dip_version/gerbers/petdisk_max_dip_top_paste.gtp: -------------------------------------------------------------------------------- 1 | G04 EAGLE Gerber RS-274X export* 2 | G75* 3 | %MOMM*% 4 | %FSLAX34Y34*% 5 | %LPD*% 6 | %INTop Solder Paste*% 7 | %IPPOS*% 8 | %AMOC8* 9 | 5,1,8,0,0,1.08239X$1,22.5*% 10 | G01* 11 | %ADD10C,0.762000*% 12 | %ADD11R,1.905000X8.255000*% 13 | 14 | 15 | D10* 16 | X577498Y49690D02* 17 | X595278Y49690D01* 18 | X595278Y6510D01* 19 | X577498Y6510D01* 20 | X577498Y49690D01* 21 | X577498Y13749D02* 22 | X595278Y13749D01* 23 | X595278Y20988D02* 24 | X577498Y20988D01* 25 | X577498Y28227D02* 26 | X595278Y28227D01* 27 | X595278Y35466D02* 28 | X577498Y35466D01* 29 | X577498Y42705D02* 30 | X595278Y42705D01* 31 | X555678Y49690D02* 32 | X537898Y49690D01* 33 | X555678Y49690D02* 34 | X555678Y6510D01* 35 | X537898Y6510D01* 36 | X537898Y49690D01* 37 | X537898Y13749D02* 38 | X555678Y13749D01* 39 | X555678Y20988D02* 40 | X537898Y20988D01* 41 | X537898Y28227D02* 42 | X555678Y28227D01* 43 | X555678Y35466D02* 44 | X537898Y35466D01* 45 | X537898Y42705D02* 46 | X555678Y42705D01* 47 | X516078Y49690D02* 48 | X498298Y49690D01* 49 | X516078Y49690D02* 50 | X516078Y6510D01* 51 | X498298Y6510D01* 52 | X498298Y49690D01* 53 | X498298Y13749D02* 54 | X516078Y13749D01* 55 | X516078Y20988D02* 56 | X498298Y20988D01* 57 | X498298Y28227D02* 58 | X516078Y28227D01* 59 | X516078Y35466D02* 60 | X498298Y35466D01* 61 | X498298Y42705D02* 62 | X516078Y42705D01* 63 | X476478Y49690D02* 64 | X458698Y49690D01* 65 | X476478Y49690D02* 66 | X476478Y6510D01* 67 | X458698Y6510D01* 68 | X458698Y49690D01* 69 | X458698Y13749D02* 70 | X476478Y13749D01* 71 | X476478Y20988D02* 72 | X458698Y20988D01* 73 | X458698Y28227D02* 74 | X476478Y28227D01* 75 | X476478Y35466D02* 76 | X458698Y35466D01* 77 | X458698Y42705D02* 78 | X476478Y42705D01* 79 | X436878Y49690D02* 80 | X419098Y49690D01* 81 | X436878Y49690D02* 82 | X436878Y6510D01* 83 | X419098Y6510D01* 84 | X419098Y49690D01* 85 | X419098Y13749D02* 86 | X436878Y13749D01* 87 | X436878Y20988D02* 88 | X419098Y20988D01* 89 | X419098Y28227D02* 90 | X436878Y28227D01* 91 | X436878Y35466D02* 92 | X419098Y35466D01* 93 | X419098Y42705D02* 94 | X436878Y42705D01* 95 | X397278Y49690D02* 96 | X379498Y49690D01* 97 | X397278Y49690D02* 98 | X397278Y6510D01* 99 | X379498Y6510D01* 100 | X379498Y49690D01* 101 | X379498Y13749D02* 102 | X397278Y13749D01* 103 | X397278Y20988D02* 104 | X379498Y20988D01* 105 | X379498Y28227D02* 106 | X397278Y28227D01* 107 | X397278Y35466D02* 108 | X379498Y35466D01* 109 | X379498Y42705D02* 110 | X397278Y42705D01* 111 | X357678Y49690D02* 112 | X339898Y49690D01* 113 | X357678Y49690D02* 114 | X357678Y6510D01* 115 | X339898Y6510D01* 116 | X339898Y49690D01* 117 | X339898Y13749D02* 118 | X357678Y13749D01* 119 | X357678Y20988D02* 120 | X339898Y20988D01* 121 | X339898Y28227D02* 122 | X357678Y28227D01* 123 | X357678Y35466D02* 124 | X339898Y35466D01* 125 | X339898Y42705D02* 126 | X357678Y42705D01* 127 | X318078Y49690D02* 128 | X300298Y49690D01* 129 | X318078Y49690D02* 130 | X318078Y6510D01* 131 | X300298Y6510D01* 132 | X300298Y49690D01* 133 | X300298Y13749D02* 134 | X318078Y13749D01* 135 | X318078Y20988D02* 136 | X300298Y20988D01* 137 | X300298Y28227D02* 138 | X318078Y28227D01* 139 | X318078Y35466D02* 140 | X300298Y35466D01* 141 | X300298Y42705D02* 142 | X318078Y42705D01* 143 | X278478Y49690D02* 144 | X260698Y49690D01* 145 | X278478Y49690D02* 146 | X278478Y6510D01* 147 | X260698Y6510D01* 148 | X260698Y49690D01* 149 | X260698Y13749D02* 150 | X278478Y13749D01* 151 | X278478Y20988D02* 152 | X260698Y20988D01* 153 | X260698Y28227D02* 154 | X278478Y28227D01* 155 | X278478Y35466D02* 156 | X260698Y35466D01* 157 | X260698Y42705D02* 158 | X278478Y42705D01* 159 | X238878Y49690D02* 160 | X221098Y49690D01* 161 | X238878Y49690D02* 162 | X238878Y6510D01* 163 | X221098Y6510D01* 164 | X221098Y49690D01* 165 | X221098Y13749D02* 166 | X238878Y13749D01* 167 | X238878Y20988D02* 168 | X221098Y20988D01* 169 | X221098Y28227D02* 170 | X238878Y28227D01* 171 | X238878Y35466D02* 172 | X221098Y35466D01* 173 | X221098Y42705D02* 174 | X238878Y42705D01* 175 | X199278Y49690D02* 176 | X181498Y49690D01* 177 | X199278Y49690D02* 178 | X199278Y6510D01* 179 | X181498Y6510D01* 180 | X181498Y49690D01* 181 | X181498Y13749D02* 182 | X199278Y13749D01* 183 | X199278Y20988D02* 184 | X181498Y20988D01* 185 | X181498Y28227D02* 186 | X199278Y28227D01* 187 | X199278Y35466D02* 188 | X181498Y35466D01* 189 | X181498Y42705D02* 190 | X199278Y42705D01* 191 | X159678Y49690D02* 192 | X141898Y49690D01* 193 | X159678Y49690D02* 194 | X159678Y6510D01* 195 | X141898Y6510D01* 196 | X141898Y49690D01* 197 | X141898Y13749D02* 198 | X159678Y13749D01* 199 | X159678Y20988D02* 200 | X141898Y20988D01* 201 | X141898Y28227D02* 202 | X159678Y28227D01* 203 | X159678Y35466D02* 204 | X141898Y35466D01* 205 | X141898Y42705D02* 206 | X159678Y42705D01* 207 | D11* 208 | X193800Y330540D03* 209 | X233400Y330540D03* 210 | X273000Y330540D03* 211 | X312600Y330540D03* 212 | X352200Y330540D03* 213 | X391800Y330540D03* 214 | X431400Y330540D03* 215 | X471000Y330540D03* 216 | X510600Y330540D03* 217 | X550200Y330540D03* 218 | X589800Y330540D03* 219 | X154200Y330540D03* 220 | M02* 221 | -------------------------------------------------------------------------------- /schematics/dip_version/gerbers/petdisk_max_dip_top_soldermask.gts: -------------------------------------------------------------------------------- 1 | G04 EAGLE Gerber RS-274X export* 2 | G75* 3 | %MOMM*% 4 | %FSLAX34Y34*% 5 | %LPD*% 6 | %INTop Soldermask*% 7 | %IPPOS*% 8 | %AMOC8* 9 | 5,1,8,0,0,1.08239X$1,22.5*% 10 | G01* 11 | %ADD10C,0.553200*% 12 | %ADD11R,1.614400X1.614400*% 13 | %ADD12C,1.614400*% 14 | %ADD13C,0.960119*% 15 | %ADD14C,1.003200*% 16 | %ADD15R,2.032000X2.032000*% 17 | %ADD16P,2.199416X8X292.500000*% 18 | %ADD17R,1.643200X1.643200*% 19 | %ADD18C,1.643200*% 20 | %ADD19P,2.254402X8X22.500000*% 21 | %ADD20R,2.108200X8.458200*% 22 | %ADD21C,0.705600*% 23 | 24 | 25 | D10* 26 | X575000Y265000D03* 27 | X610000Y265000D03* 28 | D11* 29 | X628000Y243950D03* 30 | D12* 31 | X602600Y243950D03* 32 | X577200Y243950D03* 33 | X551800Y243950D03* 34 | X526400Y243950D03* 35 | X501000Y243950D03* 36 | X475600Y243950D03* 37 | X450200Y243950D03* 38 | X424800Y243950D03* 39 | X399400Y243950D03* 40 | X374000Y243950D03* 41 | X348600Y243950D03* 42 | X323200Y243950D03* 43 | X297800Y243950D03* 44 | X272400Y243950D03* 45 | X247000Y243950D03* 46 | X221600Y243950D03* 47 | X196200Y243950D03* 48 | X170800Y243950D03* 49 | X145400Y243950D03* 50 | X145400Y89650D03* 51 | X170800Y89650D03* 52 | X196200Y89650D03* 53 | X221600Y89650D03* 54 | X247000Y89650D03* 55 | X272400Y89650D03* 56 | X297800Y89650D03* 57 | X323200Y89650D03* 58 | X348600Y89650D03* 59 | X374000Y89650D03* 60 | X399400Y89650D03* 61 | X424800Y89650D03* 62 | X450200Y89650D03* 63 | X475600Y89650D03* 64 | X501000Y89650D03* 65 | X526400Y89650D03* 66 | X551800Y89650D03* 67 | X577200Y89650D03* 68 | X602600Y89650D03* 69 | X628000Y89650D03* 70 | D13* 71 | X595304Y49716D02* 72 | X577472Y49716D01* 73 | X595304Y49716D02* 74 | X595304Y6484D01* 75 | X577472Y6484D01* 76 | X577472Y49716D01* 77 | X577472Y15605D02* 78 | X595304Y15605D01* 79 | X595304Y24726D02* 80 | X577472Y24726D01* 81 | X577472Y33847D02* 82 | X595304Y33847D01* 83 | X595304Y42968D02* 84 | X577472Y42968D01* 85 | X555704Y49716D02* 86 | X537872Y49716D01* 87 | X555704Y49716D02* 88 | X555704Y6484D01* 89 | X537872Y6484D01* 90 | X537872Y49716D01* 91 | X537872Y15605D02* 92 | X555704Y15605D01* 93 | X555704Y24726D02* 94 | X537872Y24726D01* 95 | X537872Y33847D02* 96 | X555704Y33847D01* 97 | X555704Y42968D02* 98 | X537872Y42968D01* 99 | X516104Y49716D02* 100 | X498272Y49716D01* 101 | X516104Y49716D02* 102 | X516104Y6484D01* 103 | X498272Y6484D01* 104 | X498272Y49716D01* 105 | X498272Y15605D02* 106 | X516104Y15605D01* 107 | X516104Y24726D02* 108 | X498272Y24726D01* 109 | X498272Y33847D02* 110 | X516104Y33847D01* 111 | X516104Y42968D02* 112 | X498272Y42968D01* 113 | X476504Y49716D02* 114 | X458672Y49716D01* 115 | X476504Y49716D02* 116 | X476504Y6484D01* 117 | X458672Y6484D01* 118 | X458672Y49716D01* 119 | X458672Y15605D02* 120 | X476504Y15605D01* 121 | X476504Y24726D02* 122 | X458672Y24726D01* 123 | X458672Y33847D02* 124 | X476504Y33847D01* 125 | X476504Y42968D02* 126 | X458672Y42968D01* 127 | X436904Y49716D02* 128 | X419072Y49716D01* 129 | X436904Y49716D02* 130 | X436904Y6484D01* 131 | X419072Y6484D01* 132 | X419072Y49716D01* 133 | X419072Y15605D02* 134 | X436904Y15605D01* 135 | X436904Y24726D02* 136 | X419072Y24726D01* 137 | X419072Y33847D02* 138 | X436904Y33847D01* 139 | X436904Y42968D02* 140 | X419072Y42968D01* 141 | X397304Y49716D02* 142 | X379472Y49716D01* 143 | X397304Y49716D02* 144 | X397304Y6484D01* 145 | X379472Y6484D01* 146 | X379472Y49716D01* 147 | X379472Y15605D02* 148 | X397304Y15605D01* 149 | X397304Y24726D02* 150 | X379472Y24726D01* 151 | X379472Y33847D02* 152 | X397304Y33847D01* 153 | X397304Y42968D02* 154 | X379472Y42968D01* 155 | X357704Y49716D02* 156 | X339872Y49716D01* 157 | X357704Y49716D02* 158 | X357704Y6484D01* 159 | X339872Y6484D01* 160 | X339872Y49716D01* 161 | X339872Y15605D02* 162 | X357704Y15605D01* 163 | X357704Y24726D02* 164 | X339872Y24726D01* 165 | X339872Y33847D02* 166 | X357704Y33847D01* 167 | X357704Y42968D02* 168 | X339872Y42968D01* 169 | X318104Y49716D02* 170 | X300272Y49716D01* 171 | X318104Y49716D02* 172 | X318104Y6484D01* 173 | X300272Y6484D01* 174 | X300272Y49716D01* 175 | X300272Y15605D02* 176 | X318104Y15605D01* 177 | X318104Y24726D02* 178 | X300272Y24726D01* 179 | X300272Y33847D02* 180 | X318104Y33847D01* 181 | X318104Y42968D02* 182 | X300272Y42968D01* 183 | X278504Y49716D02* 184 | X260672Y49716D01* 185 | X278504Y49716D02* 186 | X278504Y6484D01* 187 | X260672Y6484D01* 188 | X260672Y49716D01* 189 | X260672Y15605D02* 190 | X278504Y15605D01* 191 | X278504Y24726D02* 192 | X260672Y24726D01* 193 | X260672Y33847D02* 194 | X278504Y33847D01* 195 | X278504Y42968D02* 196 | X260672Y42968D01* 197 | X238904Y49716D02* 198 | X221072Y49716D01* 199 | X238904Y49716D02* 200 | X238904Y6484D01* 201 | X221072Y6484D01* 202 | X221072Y49716D01* 203 | X221072Y15605D02* 204 | X238904Y15605D01* 205 | X238904Y24726D02* 206 | X221072Y24726D01* 207 | X221072Y33847D02* 208 | X238904Y33847D01* 209 | X238904Y42968D02* 210 | X221072Y42968D01* 211 | X199304Y49716D02* 212 | X181472Y49716D01* 213 | X199304Y49716D02* 214 | X199304Y6484D01* 215 | X181472Y6484D01* 216 | X181472Y49716D01* 217 | X181472Y15605D02* 218 | X199304Y15605D01* 219 | X199304Y24726D02* 220 | X181472Y24726D01* 221 | X181472Y33847D02* 222 | X199304Y33847D01* 223 | X199304Y42968D02* 224 | X181472Y42968D01* 225 | X159704Y49716D02* 226 | X141872Y49716D01* 227 | X159704Y49716D02* 228 | X159704Y6484D01* 229 | X141872Y6484D01* 230 | X141872Y49716D01* 231 | X141872Y15605D02* 232 | X159704Y15605D01* 233 | X159704Y24726D02* 234 | X141872Y24726D01* 235 | X141872Y33847D02* 236 | X159704Y33847D01* 237 | X159704Y42968D02* 238 | X141872Y42968D01* 239 | D14* 240 | X17500Y125500D03* 241 | X17500Y205500D03* 242 | D15* 243 | X697700Y89800D03* 244 | D16* 245 | X723100Y89800D03* 246 | X697700Y64400D03* 247 | X723100Y64400D03* 248 | X697700Y39000D03* 249 | X723100Y39000D03* 250 | D17* 251 | X315025Y127750D03* 252 | X315025Y203950D03* 253 | D18* 254 | X315025Y153150D03* 255 | X315025Y178550D03* 256 | X289625Y178550D03* 257 | X289625Y153150D03* 258 | X289625Y127750D03* 259 | X289625Y203950D03* 260 | D19* 261 | X24600Y62700D03* 262 | X24600Y37300D03* 263 | X50000Y62700D03* 264 | X50000Y37300D03* 265 | X75400Y62700D03* 266 | X75400Y37300D03* 267 | D20* 268 | X193800Y330540D03* 269 | X233400Y330540D03* 270 | X273000Y330540D03* 271 | X312600Y330540D03* 272 | X352200Y330540D03* 273 | X391800Y330540D03* 274 | X431400Y330540D03* 275 | X471000Y330540D03* 276 | X510600Y330540D03* 277 | X550200Y330540D03* 278 | X589800Y330540D03* 279 | X154200Y330540D03* 280 | D21* 281 | X362500Y107500D03* 282 | X262500Y100000D03* 283 | X216000Y109000D03* 284 | X269000Y59536D03* 285 | X212000Y149000D03* 286 | X212000Y164000D03* 287 | X224000Y215000D03* 288 | X234000Y249000D03* 289 | X645000Y140000D03* 290 | X622500Y280000D03* 291 | X635000Y140000D03* 292 | X600000Y274036D03* 293 | X497500Y177500D03* 294 | X485000Y267500D03* 295 | X487500Y177500D03* 296 | X472500Y267500D03* 297 | X440000Y125000D03* 298 | X432500Y267500D03* 299 | X200000Y270000D03* 300 | X250000Y270000D03* 301 | X295000Y270000D03* 302 | X335000Y270000D03* 303 | X375000Y270000D03* 304 | X410000Y270000D03* 305 | X410000Y185000D03* 306 | X375000Y185000D03* 307 | X375000Y220000D03* 308 | X335000Y220000D03* 309 | X260000Y235000D03* 310 | X260000Y215000D03* 311 | X225000Y195000D03* 312 | X205000Y195000D03* 313 | X225000Y155000D03* 314 | X200000Y160000D03* 315 | X260000Y140000D03* 316 | X235000Y140000D03* 317 | X455000Y270000D03* 318 | X460000Y220000D03* 319 | X460000Y175000D03* 320 | X460000Y135000D03* 321 | X475000Y135000D03* 322 | X515000Y135000D03* 323 | X515000Y170000D03* 324 | X515000Y220000D03* 325 | X550000Y220000D03* 326 | X575000Y220000D03* 327 | X575000Y170000D03* 328 | X550000Y170000D03* 329 | X575000Y115000D03* 330 | X575000Y75000D03* 331 | X553000Y104000D03* 332 | X240000Y75000D03* 333 | X140000Y270000D03* 334 | X410000Y65000D03* 335 | X367500Y62500D03* 336 | X327500Y57500D03* 337 | X290000Y55000D03* 338 | X250000Y50000D03* 339 | X567500Y57500D03* 340 | X527500Y50000D03* 341 | X485000Y62500D03* 342 | X537500Y65000D03* 343 | X452500Y65000D03* 344 | X105000Y117500D03* 345 | X110000Y162500D03* 346 | X102500Y175000D03* 347 | X402500Y255000D03* 348 | X422500Y255000D03* 349 | X50000Y120000D03* 350 | X475000Y177500D03* 351 | X95000Y152500D03* 352 | X450000Y177500D03* 353 | M02* 354 | -------------------------------------------------------------------------------- /schematics/dip_version/petdisk_max_dip_partlist.txt: -------------------------------------------------------------------------------- 1 | Partlist 2 | 3 | Exported from petdisk_max_dip.brd at 26.01.22 23.24 4 | 5 | EAGLE Version 9.6.1 Copyright (c) 1988-2020 Autodesk, Inc. 6 | 7 | Assembly variant: 8 | 9 | Part Value Package Library Position (mm) Orientation 10 | 11 | C1 10uF 1206 SparkFun-Capacitors (72.5 17.5) MR90 12 | C2 10uF 1206 SparkFun-Capacitors (62.5 17.5) MR270 13 | C3 0.1uF 0603-CAP SparkFun-Capacitors (39.3 20.7) MR90 14 | C5 0.1uF 0603-CAP SparkFun-Capacitors (26 18.3) MR90 15 | C6 10uF 1206 SparkFun-Capacitors (16.2 18.5) MR90 16 | C7 0.1uF 0603-CAP SparkFun-Capacitors (18.55 17.95) MR90 17 | C8 10uF 1206 SparkFun-Capacitors (23.9 18.5) MR90 18 | C9 10uF 1206 SparkFun-Capacitors (60 17.5) MR270 19 | D1 RED LED-0603 SparkFun-LED (61 26.5) MR270 20 | D2 RED LED-0603 SparkFun-LED (57.5 26.5) MR270 21 | IC1 ATMEGA1284P-PU DIP1543W58P254L5175H635Q40N rakettitiede (38.67 16.68) R270 22 | IC2 NCP1117LPST33T3G SOT230P700X180-4N rakettitiede (67.5 17.5) MR270 23 | ISP AVR_SPI_PRG_6NS 2X3-NS SparkFun-Connectors (5 5) MR180 24 | MOD USD-SOCKET-CHINA USD-SOCKET-PP BaseApp (13.5 17.5) MR90 25 | MOD1 ESP01 ESP01 esp8266 (37.14 16.6) MR90 26 | PWRIN 2X03 pinhead-2 (71.04 6.44) R270 27 | R1 1K 0603-RES SparkFun-Resistors (42.3 21.5) MR180 28 | R2 1K 0603-RES SparkFun-Resistors (54 26.5) MR180 29 | R3 1K 0603-RES SparkFun-Resistors (50.5 26.5) MR180 30 | U$1 CBM_IEEE_CONN UPS24CONN commodore (36.86 1.54) R180 31 | U$4 24PINEDGE 24PINEDGE commodore (37.2 32.8) R180 32 | -------------------------------------------------------------------------------- /schematics/petdisk_esp32.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bitfixer/petdisk-max/7ca0859926249b7c8f7e129c2beb325d5b22a573/schematics/petdisk_esp32.pdf -------------------------------------------------------------------------------- /schematics/tape_power_adapter/gerbers/tape_power_adapter_bottom_copper.gbl: -------------------------------------------------------------------------------- 1 | G04 EAGLE Gerber RS-274X export* 2 | G75* 3 | %MOMM*% 4 | %FSLAX34Y34*% 5 | %LPD*% 6 | %INBottom Copper*% 7 | %IPPOS*% 8 | %AMOC8* 9 | 5,1,8,0,0,1.08239X$1,22.5*% 10 | G01* 11 | %ADD10R,1.905000X8.255000*% 12 | %ADD11R,2.000000X4.000000*% 13 | %ADD12C,1.108000*% 14 | %ADD13R,1.828800X1.828800*% 15 | %ADD14P,1.979475X8X292.500000*% 16 | %ADD15C,0.900000*% 17 | 18 | 19 | D10* 20 | X237700Y954540D03* 21 | X198100Y954540D03* 22 | X158500Y954540D03* 23 | X118900Y954540D03* 24 | X79300Y954540D03* 25 | X39700Y954540D03* 26 | D11* 27 | X39700Y790000D03* 28 | X79300Y790000D03* 29 | X118900Y790000D03* 30 | X158500Y790000D03* 31 | X198100Y790000D03* 32 | X237700Y790000D03* 33 | D12* 34 | X39700Y809800D03* 35 | X79300Y809800D03* 36 | X118900Y809800D03* 37 | X158500Y809800D03* 38 | X198100Y809800D03* 39 | X237700Y809800D03* 40 | D13* 41 | X207300Y881400D03* 42 | D14* 43 | X232700Y881400D03* 44 | X207300Y856000D03* 45 | X232700Y856000D03* 46 | X207300Y830600D03* 47 | X232700Y830600D03* 48 | D15* 49 | X237700Y886400D02* 50 | X237700Y954540D01* 51 | X237700Y886400D02* 52 | X232700Y881400D01* 53 | X232700Y856000D02* 54 | X232700Y830600D01* 55 | X232700Y856000D02* 56 | X232700Y881400D01* 57 | X237700Y809800D02* 58 | X237700Y790000D01* 59 | X237700Y825600D01* 60 | X232700Y830600D01* 61 | X198100Y890600D02* 62 | X198100Y954540D01* 63 | X198100Y890600D02* 64 | X207300Y881400D01* 65 | X198100Y821400D02* 66 | X198100Y809800D01* 67 | X198100Y821400D02* 68 | X207300Y830600D01* 69 | X207300Y856000D02* 70 | X207300Y881400D01* 71 | X207300Y856000D02* 72 | X207300Y830600D01* 73 | X198100Y809800D02* 74 | X198100Y790000D01* 75 | X158500Y887500D02* 76 | X158500Y954540D01* 77 | X158500Y887500D02* 78 | X164000Y882000D01* 79 | X164000Y852000D01* 80 | X158000Y846000D01* 81 | X158000Y810300D01* 82 | X158500Y809800D01* 83 | X158500Y790000D01* 84 | X118900Y886900D02* 85 | X118900Y954540D01* 86 | X118900Y886900D02* 87 | X114000Y882000D01* 88 | X114000Y852000D01* 89 | X118900Y847100D02* 90 | X118900Y809800D01* 91 | X118900Y847100D02* 92 | X114000Y852000D01* 93 | X118900Y802900D02* 94 | X118900Y790000D01* 95 | X118900Y802900D02* 96 | X120000Y804000D01* 97 | X120000Y808700D01* 98 | X118900Y809800D01* 99 | X79300Y809800D02* 100 | X79300Y954540D01* 101 | X79300Y809800D02* 102 | X79300Y790000D01* 103 | X39700Y809800D02* 104 | X39700Y954540D01* 105 | X39700Y809800D02* 106 | X39700Y790000D01* 107 | M02* 108 | -------------------------------------------------------------------------------- /schematics/tape_power_adapter/gerbers/tape_power_adapter_bottom_paste.gbp: -------------------------------------------------------------------------------- 1 | G04 EAGLE Gerber RS-274X export* 2 | G75* 3 | %MOMM*% 4 | %FSLAX34Y34*% 5 | %LPD*% 6 | %INBottom Solder Paste*% 7 | %IPPOS*% 8 | %AMOC8* 9 | 5,1,8,0,0,1.08239X$1,22.5*% 10 | G01* 11 | %ADD10R,1.905000X8.255000*% 12 | %ADD11R,2.000000X4.000000*% 13 | 14 | 15 | D10* 16 | X237700Y954540D03* 17 | X198100Y954540D03* 18 | X158500Y954540D03* 19 | X118900Y954540D03* 20 | X79300Y954540D03* 21 | X39700Y954540D03* 22 | D11* 23 | X39700Y790000D03* 24 | X79300Y790000D03* 25 | X118900Y790000D03* 26 | X158500Y790000D03* 27 | X198100Y790000D03* 28 | X237700Y790000D03* 29 | M02* 30 | -------------------------------------------------------------------------------- /schematics/tape_power_adapter/gerbers/tape_power_adapter_bottom_silk.gbo: -------------------------------------------------------------------------------- 1 | G04 EAGLE Gerber RS-274X export* 2 | G75* 3 | %MOMM*% 4 | %FSLAX34Y34*% 5 | %LPD*% 6 | %INBottom Silkscreen*% 7 | %IPPOS*% 8 | %AMOC8* 9 | 5,1,8,0,0,1.08239X$1,22.5*% 10 | G01* 11 | 12 | 13 | M02* 14 | -------------------------------------------------------------------------------- /schematics/tape_power_adapter/gerbers/tape_power_adapter_bottom_soldermask.gbs: -------------------------------------------------------------------------------- 1 | G04 EAGLE Gerber RS-274X export* 2 | G75* 3 | %MOMM*% 4 | %FSLAX34Y34*% 5 | %LPD*% 6 | %INBottom Soldermask*% 7 | %IPPOS*% 8 | %AMOC8* 9 | 5,1,8,0,0,1.08239X$1,22.5*% 10 | G01* 11 | %ADD10C,3.303200*% 12 | %ADD11R,2.108200X8.458200*% 13 | %ADD12R,2.203200X4.203200*% 14 | %ADD13C,1.311200*% 15 | %ADD14R,2.032000X2.032000*% 16 | %ADD15P,2.199416X8X292.500000*% 17 | 18 | 19 | D10* 20 | X138700Y868000D03* 21 | D11* 22 | X237700Y954540D03* 23 | X198100Y954540D03* 24 | X158500Y954540D03* 25 | X118900Y954540D03* 26 | X79300Y954540D03* 27 | X39700Y954540D03* 28 | D12* 29 | X39700Y790000D03* 30 | X79300Y790000D03* 31 | X118900Y790000D03* 32 | X158500Y790000D03* 33 | X198100Y790000D03* 34 | X237700Y790000D03* 35 | D13* 36 | X39700Y809800D03* 37 | X79300Y809800D03* 38 | X118900Y809800D03* 39 | X158500Y809800D03* 40 | X198100Y809800D03* 41 | X237700Y809800D03* 42 | D14* 43 | X207300Y881400D03* 44 | D15* 45 | X232700Y881400D03* 46 | X207300Y856000D03* 47 | X232700Y856000D03* 48 | X207300Y830600D03* 49 | X232700Y830600D03* 50 | M02* 51 | -------------------------------------------------------------------------------- /schematics/tape_power_adapter/gerbers/tape_power_adapter_drills.txt: -------------------------------------------------------------------------------- 1 | M48 2 | ;GenerationSoftware,Autodesk,EAGLE,9.6.1*% 3 | ;CreationDate,2022-01-26T14:04:49Z*% 4 | FMAT,2 5 | ICI,OFF 6 | METRIC,TZ,000.000 7 | T2C0.600 8 | T1C1.016 9 | % 10 | G90 11 | M71 12 | T1 13 | X20730Y88140 14 | X23270Y88140 15 | X20730Y85600 16 | X23270Y85600 17 | X20730Y83060 18 | X23270Y83060 19 | T2 20 | X3970Y80980 21 | X7930Y80980 22 | X11890Y80980 23 | X15850Y80980 24 | X19810Y80980 25 | X23770Y80980 26 | M30 -------------------------------------------------------------------------------- /schematics/tape_power_adapter/gerbers/tape_power_adapter_drills_NPTH.txt: -------------------------------------------------------------------------------- 1 | M48 2 | ;GenerationSoftware,Autodesk,EAGLE,9.6.1*% 3 | ;CreationDate,2022-01-26T14:04:49Z*% 4 | FMAT,2 5 | ICI,OFF 6 | METRIC,TZ,000.000 7 | T1C3.100 8 | % 9 | G90 10 | M71 11 | T1 12 | X13870Y86800 13 | M30 -------------------------------------------------------------------------------- /schematics/tape_power_adapter/gerbers/tape_power_adapter_top_copper.gtl: -------------------------------------------------------------------------------- 1 | G04 EAGLE Gerber RS-274X export* 2 | G75* 3 | %MOMM*% 4 | %FSLAX34Y34*% 5 | %LPD*% 6 | %INTop Copper*% 7 | %IPPOS*% 8 | %AMOC8* 9 | 5,1,8,0,0,1.08239X$1,22.5*% 10 | G01* 11 | %ADD10R,1.905000X8.255000*% 12 | %ADD11R,2.000000X4.000000*% 13 | %ADD12C,1.108000*% 14 | %ADD13R,1.828800X1.828800*% 15 | %ADD14P,1.979475X8X292.500000*% 16 | %ADD15C,0.900000*% 17 | 18 | 19 | D10* 20 | X39700Y954540D03* 21 | X79300Y954540D03* 22 | X118900Y954540D03* 23 | X158500Y954540D03* 24 | X198100Y954540D03* 25 | X237700Y954540D03* 26 | D11* 27 | X39700Y790000D03* 28 | X79300Y790000D03* 29 | X118900Y790000D03* 30 | X158500Y790000D03* 31 | X198100Y790000D03* 32 | X237700Y790000D03* 33 | D12* 34 | X39700Y809800D03* 35 | X79300Y809800D03* 36 | X118900Y809800D03* 37 | X158500Y809800D03* 38 | X198100Y809800D03* 39 | X237700Y809800D03* 40 | D13* 41 | X207300Y881400D03* 42 | D14* 43 | X232700Y881400D03* 44 | X207300Y856000D03* 45 | X232700Y856000D03* 46 | X207300Y830600D03* 47 | X232700Y830600D03* 48 | D15* 49 | X237700Y886400D02* 50 | X237700Y954540D01* 51 | X237700Y886400D02* 52 | X232700Y881400D01* 53 | X232700Y830600D01* 54 | X237700Y809800D02* 55 | X237700Y790000D01* 56 | X237700Y809800D02* 57 | X237700Y825600D01* 58 | X232700Y830600D01* 59 | X198100Y890600D02* 60 | X198100Y954540D01* 61 | X198100Y890600D02* 62 | X207300Y881400D01* 63 | X207300Y830600D02* 64 | X198100Y821400D01* 65 | X207300Y830600D02* 66 | X207300Y881400D01* 67 | X198100Y821400D02* 68 | X198100Y790000D01* 69 | X158500Y887500D02* 70 | X158500Y954540D01* 71 | X164000Y852000D02* 72 | X158000Y846000D01* 73 | X158000Y810300D01* 74 | X164000Y882000D02* 75 | X158500Y887500D01* 76 | X164000Y882000D02* 77 | X164000Y852000D01* 78 | X158500Y809800D02* 79 | X158500Y790000D01* 80 | X158500Y809800D02* 81 | X158000Y810300D01* 82 | X118900Y886900D02* 83 | X118900Y954540D01* 84 | X118900Y886900D02* 85 | X114000Y882000D01* 86 | X114000Y852000D01* 87 | X118900Y847100D02* 88 | X118900Y809800D01* 89 | X118900Y847100D02* 90 | X114000Y852000D01* 91 | X118900Y809800D02* 92 | X118900Y790000D01* 93 | X79300Y809800D02* 94 | X79300Y954540D01* 95 | X79300Y809800D02* 96 | X79300Y790000D01* 97 | X39700Y809800D02* 98 | X39700Y954540D01* 99 | X39700Y809800D02* 100 | X39700Y790000D01* 101 | M02* 102 | -------------------------------------------------------------------------------- /schematics/tape_power_adapter/gerbers/tape_power_adapter_top_paste.gtp: -------------------------------------------------------------------------------- 1 | G04 EAGLE Gerber RS-274X export* 2 | G75* 3 | %MOMM*% 4 | %FSLAX34Y34*% 5 | %LPD*% 6 | %INTop Solder Paste*% 7 | %IPPOS*% 8 | %AMOC8* 9 | 5,1,8,0,0,1.08239X$1,22.5*% 10 | G01* 11 | %ADD10R,1.905000X8.255000*% 12 | %ADD11R,2.000000X4.000000*% 13 | 14 | 15 | D10* 16 | X39700Y954540D03* 17 | X79300Y954540D03* 18 | X118900Y954540D03* 19 | X158500Y954540D03* 20 | X198100Y954540D03* 21 | X237700Y954540D03* 22 | D11* 23 | X39700Y790000D03* 24 | X79300Y790000D03* 25 | X118900Y790000D03* 26 | X158500Y790000D03* 27 | X198100Y790000D03* 28 | X237700Y790000D03* 29 | M02* 30 | -------------------------------------------------------------------------------- /schematics/tape_power_adapter/gerbers/tape_power_adapter_top_soldermask.gts: -------------------------------------------------------------------------------- 1 | G04 EAGLE Gerber RS-274X export* 2 | G75* 3 | %MOMM*% 4 | %FSLAX34Y34*% 5 | %LPD*% 6 | %INTop Soldermask*% 7 | %IPPOS*% 8 | %AMOC8* 9 | 5,1,8,0,0,1.08239X$1,22.5*% 10 | G01* 11 | %ADD10C,3.303200*% 12 | %ADD11R,2.108200X8.458200*% 13 | %ADD12R,2.203200X4.203200*% 14 | %ADD13C,1.311200*% 15 | %ADD14R,2.032000X2.032000*% 16 | %ADD15P,2.199416X8X292.500000*% 17 | 18 | 19 | D10* 20 | X138700Y868000D03* 21 | D11* 22 | X39700Y954540D03* 23 | X79300Y954540D03* 24 | X118900Y954540D03* 25 | X158500Y954540D03* 26 | X198100Y954540D03* 27 | X237700Y954540D03* 28 | D12* 29 | X39700Y790000D03* 30 | X79300Y790000D03* 31 | X118900Y790000D03* 32 | X158500Y790000D03* 33 | X198100Y790000D03* 34 | X237700Y790000D03* 35 | D13* 36 | X39700Y809800D03* 37 | X79300Y809800D03* 38 | X118900Y809800D03* 39 | X158500Y809800D03* 40 | X198100Y809800D03* 41 | X237700Y809800D03* 42 | D14* 43 | X207300Y881400D03* 44 | D15* 45 | X232700Y881400D03* 46 | X207300Y856000D03* 47 | X232700Y856000D03* 48 | X207300Y830600D03* 49 | X232700Y830600D03* 50 | M02* 51 | -------------------------------------------------------------------------------- /test/Makefile: -------------------------------------------------------------------------------- 1 | CC = g++ 2 | CXX = g++ 3 | 4 | CXXFLAGS = -O -Wall 5 | 6 | SRCDIR = ../src 7 | 8 | clean: 9 | rm -f d64_test 10 | rm -f ../src/*.o 11 | 12 | d64_test: $(SRCDIR)/d64_test.o $(SRCDIR)/D64DataSource.o $(SRCDIR)/fsDataSource.o $(SRCDIR)/ConsoleLogger.o 13 | $(CXX) $(SRCDIR)/d64_test.o $(SRCDIR)/D64DataSource.o $(SRCDIR)/fsDataSource.o $(SRCDIR)/ConsoleLogger.o -o d64_test -------------------------------------------------------------------------------- /www/petdisk.php: -------------------------------------------------------------------------------- 1 | = 0 && $pagesize + strlen($newentry) >= $max_page_size) 115 | { 116 | // end this page and make a new page 117 | $dir_pages[$curr_page] = $filelist."\n"; 118 | $curr_page++; 119 | $filelist = ""; 120 | } 121 | $filelist = $filelist.strtoupper($file)."\n"; 122 | } 123 | 124 | $pagesize = strlen($filelist); 125 | } 126 | 127 | // last page 128 | $dir_pages[$curr_page] = $filelist."\n"; 129 | 130 | $respbody = "\n"; 131 | if ($page == -1) 132 | { 133 | $respbody = $dir_pages[0]; 134 | } 135 | else 136 | { 137 | if ($page <= $curr_page) 138 | { 139 | $respbody = $dir_pages[$page]; 140 | } 141 | } 142 | 143 | header('Content-Length: '.strlen($respbody)); 144 | header('Content-Type: application/octet-stream'); 145 | echo $respbody; 146 | flush(); 147 | } 148 | else 149 | { 150 | // requesting a range of bytes 151 | $start = getParam('s'); 152 | $end = getParam('e'); 153 | 154 | if ($file == "TIME") 155 | { 156 | $currentDate = new DateTime(); 157 | $currentDate->setTimezone(new DateTimeZone("UTC")); 158 | $formattedDate = $currentDate->format("Y-m-d H:i:s\n"); 159 | $content_length = strlen($formattedDate); 160 | header('Content-Length: '.$content_length); 161 | header('Content-Type: application/octet-stream'); 162 | echo $formattedDate; 163 | flush(); 164 | return; 165 | } 166 | 167 | if (fileExists($file)) { 168 | $contents = ""; 169 | if ($end > 0) { 170 | $fp = fopen($file, "r"); 171 | fseek($fp, $start, SEEK_SET); 172 | $contents = fread($fp, $end-$start); 173 | fclose($fp); 174 | $content_length = $end-$start; 175 | } else { 176 | $contents = file_get_contents($file); 177 | } 178 | header('Content-Length: '.$content_length); 179 | header('Content-Type: application/octet-stream'); 180 | echo $contents; 181 | flush(); 182 | } else { 183 | error_log("file " . $file . " does not exist"); 184 | } 185 | } 186 | } 187 | } 188 | else if ($verb == "PUT") 189 | { 190 | if ($PETDISK_READ_ONLY == true) 191 | { 192 | // ignore writes for read only mode 193 | return; 194 | } 195 | $fname = $_GET['f']; 196 | $new = getParam('n'); 197 | 198 | // read put data 199 | $putdata = ''; 200 | if (getParam('b64')) { 201 | $base64data = file_get_contents("php://input"); 202 | $putdata = base64_decode($base64data); 203 | } else { 204 | $putdata = file_get_contents("php://input"); 205 | } 206 | 207 | $full_fname = ""; 208 | if ($fname) 209 | { 210 | $full_fname = "./".$fname; 211 | } 212 | 213 | $exists = false; 214 | if ($full_fname != "") 215 | { 216 | $exists = file_exists($full_fname); 217 | } 218 | 219 | // remove existing file if new specified 220 | $file_contents = ""; 221 | if ($exists == true && $new == 1) 222 | { 223 | unlink($full_fname); 224 | $exists = false; 225 | } 226 | 227 | if (getParam('u') == 1) // update specific block 228 | { 229 | $start = $_GET['s']; 230 | $end = $_GET['e']; 231 | 232 | // check to see if file is large enough 233 | $foundFname = fileExists($fname); 234 | if ($foundFname != false) 235 | { 236 | $fp = fopen($foundFname, "r+"); 237 | fseek($fp, $start); 238 | fwrite($fp, $putdata, $end-$start); 239 | fclose($fp); 240 | } 241 | else 242 | { 243 | error_log("file not found: " . $fname); 244 | } 245 | } 246 | else // append block to end of file 247 | { 248 | if ($exists == true) 249 | { 250 | $file_contents = file_get_contents($full_fname); 251 | } 252 | 253 | // append new data 254 | $file_contents = $file_contents . $putdata; 255 | // rewrite file 256 | file_put_contents($full_fname, $file_contents); 257 | } 258 | } 259 | 260 | 261 | ?> 262 | --------------------------------------------------------------------------------