-
Notifications
You must be signed in to change notification settings - Fork 0
/
ops.h
99 lines (89 loc) · 3.18 KB
/
ops.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/****************************************************************************
* *
* PICO-SST39SF0x0-FLASHER-FIRMWARE *
* Copyright (C) 2023 Ivo Filot <ivo@ivofilot.nl> *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public license *
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
* *
****************************************************************************/
#ifndef _OPS_H
#define _OPS_H
#include <pico/stdlib.h>
#include <stdio.h>
#include "constants.h"
/**
* @brief Load address in 74HC573 chips
*
* @param addr The full 19-bit address
**/
void set_address(uint32_t addr);
/**
* @brief Set the 3 upper address bits
*
* @param addr The bits to set
*/
inline static void set_address_upper(uint32_t addr) {
gpio_put_masked(0x0700, addr << 8);
gpio_put(AUS, true);
sleep_us(DELAY_ADDR);
gpio_put(AUS, false);
}
/**
* @brief Set higher 8 bits in address register
*
* @param addr The bits to set
**/
inline static void set_address_high(uint32_t addr) {
gpio_put_masked(0xFF00, addr << 8);
gpio_put(AHS, true);
sleep_us(DELAY_ADDR);
gpio_put(AHS, false);
}
/**
* @brief Set lower 8 bits in address register
*
* @param addr The bits to set
**/
inline static void set_address_low(uint32_t addr) {
gpio_put_masked(0xFF00, addr << 8);
gpio_put(ALS, true);
sleep_us(DELAY_ADDR);
gpio_put(ALS, false);
}
/**
* @brief Read a single byte from address
*
* @param addr full 19-bit address
* @return uint8_t value at address
*/
uint8_t read_byte(uint32_t addr);
/**
* @brief Write a byte at address
*
* @param addr full 19-bit address
* @param val 8-bit value to write
*/
void write_byte(uint32_t addr, uint8_t val);
/**
* @brief Write byte at address while ignoring any upper bytes
*
* @param addr 16-bit combination of lower and higher address bits
* @param val 8-bit value to write
*
* Assumes that:
* - Pins are already set for output
* - Chip is already active (CE)
**/
void write_byte_ignore_upper_fast(uint16_t addr, uint8_t val);
#endif