size_t TwoWire::requestFrom(uint8_t address, size_t size, bool sendStop){ if(size > BUFFER_LENGTH){ size = BUFFER_LENGTH; } //size_t read = (twi_readFrom(address, rxBuffer, size, sendStop) == 0)?size:0; //rxBufferIndex = 0; //rxBufferLength = read; //return read; brzo_i2c_read(rxBuffer, size, !sendStop); rxBufferIndex = 0; rxBufferLength = size; return size; }
uint8_t init_pca9685(uint8_t addr) { uint8_t rc; uint8_t bytes[2]; ets_printf("PCA9685 init ... "); // Write MODE1 register (key bits are to set auto-increment and turn off sleep mode bytes[0] = 0x00; // MODE1 register bytes[1] = 0b00100001; // reset = 1, AI = 1, sleep = 0, allcall = 1 brzo_i2c_start_transaction(addr, 100); brzo_i2c_write(bytes, 2, FALSE); rc = brzo_i2c_end_transaction(); if (rc) { ets_printf("failed write: %d\r\n", rc); goto EXIT_LABEL; } // Now read back the register to check it took brzo_i2c_start_transaction(addr, 100); brzo_i2c_write(bytes, 1, FALSE); brzo_i2c_read(bytes, 1, FALSE); rc = brzo_i2c_end_transaction(); if (!rc) { if (bytes[0] == bytes[1]) { ets_printf("success\r\n"); goto EXIT_LABEL; } else { ets_printf("failed read mismatch: 0x%02x\r\n", bytes[0]); } } else { ets_printf("failed read: %d\r\n", rc); } EXIT_LABEL: return rc; }