potentiometer.c 1.1 KB

1234567891011121314151617181920212223242526
  1. #include "potentiometer.h"
  2. void potentiometer_set(void *bar1, uint8_t pot_val_ch_a, uint8_t pot_val_ch_b) {
  3. usleep(1);
  4. uint32_t cfg_reg = get_cfg_reg();
  5. SET_REGISTER_PARAM(cfg_reg, CFG_REG_SPI_MODE_BITM, CFG_REG_SPI_MODE_BITP, CFG_REG_SPI_MODE_4MOSI);
  6. uint32_t *spi_mode = bar1 + CFG_REG_ADDR;
  7. *spi_mode = cfg_reg;
  8. uint32_t pot_ch_a = (TPL0202_CMD_WR_WIPER_REG_ENUM << TPL0202_CMD_BITP)|(TPL0202_ADR_B_ENUM << TPL0202_ADR_BITP)|(pot_val_ch_a << TPL0202_DATA_BITP);
  9. uint32_t pot_ch_b = (TPL0202_CMD_WR_WIPER_REG_ENUM << TPL0202_CMD_BITP)|(TPL0202_ADR_A_ENUM << TPL0202_ADR_BITP)|(pot_val_ch_b << TPL0202_DATA_BITP);
  10. // Create a header for the Potentiometer 4MOSI
  11. uint32_t pot_header = (ENUM_SPIMODE_4MOSI | (0x2 << BITP_POT_4MOSI_HEADER) | SB_HEADER_TERM_BIT_1);
  12. uint32_t *ptr = bar1 + LMX_BASE_ADDR;
  13. *ptr = pot_header;
  14. // Send the data
  15. *ptr = pot_ch_a;
  16. *ptr = pot_ch_b;
  17. usleep(1);
  18. SET_REGISTER_PARAM(cfg_reg, CFG_REG_SPI_MODE_BITM, CFG_REG_SPI_MODE_BITP, CFG_REG_SPI_MODE_1MOSI);
  19. *spi_mode = cfg_reg;
  20. set_cfg_reg(cfg_reg);
  21. usleep(1);
  22. }