import spidev
import time

cc2500_config = {
    0x00: 0x0B,  # IOCFG2
    0x02: 0x06,  # IOCFG0
    0x03: 0x00,  # FIFOTHR
    0x07: 0x08,  # FSCTRL1
    0x08: 0x00,  # FSCTRL0
    0x0B: 0x06,  # IOCFG0 (repeating correct setting)
    0x0C: 0x00,  # FIFOTHR
    0x0D: 0x5D,  # FREQ2
    0x0E: 0x93,  # FREQ1
    0x0F: 0xB1,  # FREQ0
    0x10: 0x2D,  # MDMCFG4
    0x11: 0x3B,  # MDMCFG3
    0x12: 0x73,  # MDMCFG2
    0x15: 0x00,  # DEVIATN
    0x18: 0x18,  # MCSM0
    0x19: 0x1D,  # FOCCFG
    0x1A: 0x1C,  # BSCFG
    0x1B: 0xC7,  # AGCCTRL2
    0x22: 0x11,  # FREND0
    0x23: 0xE9,  # FSCAL3
    0x24: 0x2A,  # FSCAL2
    0x25: 0x00,  # FSCAL1
    0x26: 0x1F,  # FSCAL0
    0x2C: 0x81,  # TEST2
    0x2D: 0x35,  # TEST1
    0x2E: 0x09,  # TEST0
    0x06: 0x00,  # ADDR (only once)
    0x1E: 0x05,  # PKTCTRL0
    0x07: 0x00,  # CHANNR
}


spi = spidev.SpiDev()
spi.open(0, 0)  # Bus 0, CE0
spi.max_speed_hz = 500000  # Adjust if needed
spi.mode = 0  # CC2500 usually works in SPI mode 0

def cc2500_strobe(command):
    resp = spi.xfer2([command])
    return resp[0]

SRES = 0x30  # Reset strobe command

print("Sending reset to CC2500...")
status = cc2500_strobe(SRES)
print(f"Status byte: 0x{status:02X}")
