Merge pull request #917 from miek/operacake-addresses

Switch to using 0-7 for Opera Cake addresses
This commit is contained in:
Michael Ossmann
2021-07-15 14:30:04 -06:00
committed by GitHub
6 changed files with 34 additions and 14 deletions

View File

@ -68,14 +68,27 @@
#define OPERACAKE_POLARITY_NORMAL (0x00)
#define OPERACAKE_DEFAULT_ADDRESS 0x18
#define OPERACAKE_ADDRESS_DEFAULT 0x18
#define OPERACAKE_ADDRESS_INVALID 0xFF
i2c_bus_t* const oc_bus = &i2c0;
uint8_t operacake_boards[8] = {0,0,0,0,0,0,0,0};
uint8_t operacake_boards[8] = {
OPERACAKE_ADDRESS_INVALID,
OPERACAKE_ADDRESS_INVALID,
OPERACAKE_ADDRESS_INVALID,
OPERACAKE_ADDRESS_INVALID,
OPERACAKE_ADDRESS_INVALID,
OPERACAKE_ADDRESS_INVALID,
OPERACAKE_ADDRESS_INVALID,
OPERACAKE_ADDRESS_INVALID,
};
bool allow_gpio_mode = true;
/* read single register */
uint8_t operacake_read_reg(i2c_bus_t* const bus, uint8_t address, uint8_t reg) {
// Convert from Opera Cake address (0-7) to I2C address
address += OPERACAKE_ADDRESS_DEFAULT;
const uint8_t data_tx[] = { reg };
uint8_t data_rx[] = { 0x00 };
i2c_bus_transfer(bus, address, data_tx, 1, data_rx, 1);
@ -84,15 +97,17 @@ uint8_t operacake_read_reg(i2c_bus_t* const bus, uint8_t address, uint8_t reg) {
/* Write to one of the PCA9557 registers */
void operacake_write_reg(i2c_bus_t* const bus, uint8_t address, uint8_t reg, uint8_t value) {
// Convert from Opera Cake address (0-7) to I2C address
address += OPERACAKE_ADDRESS_DEFAULT;
const uint8_t data[] = {reg, value};
i2c_bus_transfer(bus, address, data, 2, NULL, 0);
}
uint8_t operacake_init(bool allow_gpio) {
uint8_t reg, addr, i, j = 0;
uint8_t reg, addr, j = 0;
/* Find connected operacakes */
for(i=0; i<8; i++) {
addr = OPERACAKE_DEFAULT_ADDRESS | i;
for(addr=0; addr<8; addr++) {
operacake_write_reg(oc_bus, addr, OPERACAKE_REG_OUTPUT,
OPERACAKE_DEFAULT_OUTPUT);
operacake_write_reg(oc_bus, addr, OPERACAKE_REG_CONFIG,

View File

@ -36,7 +36,7 @@
#define USB_PRODUCT_ID (0xFFFF)
#endif
#define USB_API_VERSION (0x0104)
#define USB_API_VERSION (0x0105)
#define USB_WORD(x) (x & 0xFF), ((x >> 8) & 0xFF)

View File

@ -120,9 +120,9 @@ int main(void)
}
if(result == HACKRF_SUCCESS) {
for(j=0; j<8; j++) {
if(operacakes[j] == 0)
if(operacakes[j] == HACKRF_OPERACAKE_ADDRESS_INVALID)
break;
printf("Operacake found, address: 0x%02x\n", operacakes[j]);
printf("Opera Cake found, address: %d\n", operacakes[j]);
}
}

View File

@ -265,10 +265,10 @@ int main(int argc, char** argv) {
hackrf_error_name(result), result);
return EXIT_FAILURE;
}
printf("Operacakes found: ");
printf("Opera Cakes found: ");
for(i=0; i<8; i++) {
if(operacakes[i] !=0) {
printf("\n%d", operacakes[i]);
if(operacakes[i] != HACKRF_OPERACAKE_ADDRESS_INVALID) {
printf("\n\tAddress: %d", operacakes[i]);
operacake_count++;
}
}

View File

@ -2090,12 +2090,16 @@ int ADDCALL hackrf_init_sweep(hackrf_device* device,
}
}
/* Retrieve list of Operacake board addresses
* boards must be *uint8_t[8]
/**
* Retrieve list of Opera Cake board addresses
* @param[in] device
* @param[out] boards List of board addresses. Must point to a `uint8_t[8]`. If the number of boards is less than 8, extra entries are filled with @ref HACKRF_OPERACAKE_ADDRESS_INVALID.
* @return @ref HACKRF_SUCCESS
* @return @ref HACKRF_ERROR_LIBUSB
*/
int ADDCALL hackrf_get_operacake_boards(hackrf_device* device, uint8_t* boards)
{
USB_API_REQUIRED(device, 0x0102)
USB_API_REQUIRED(device, 0x0105)
int result;
result = libusb_control_transfer(
device->usb_device,

View File

@ -50,6 +50,7 @@ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSI
#define SAMPLES_PER_BLOCK 8192
#define BYTES_PER_BLOCK 16384
#define MAX_SWEEP_RANGES 10
#define HACKRF_OPERACAKE_ADDRESS_INVALID 0xFF
enum hackrf_error {
HACKRF_SUCCESS = 0,