codegen:
  class: Nrf24l01
  instance: nrf24l01
  includes: ['driver/nrf24l01.h']
  flags: ['drivers=nrf24l01', 'arch_drivers=spi']

dummygen:
  enum:
    rf24_pa_dbm_e:
      - RF24_PA_MIN
      - RF24_PA_LOW
      - RF24_PA_HIGH
      - RF24_PA_MAX
      - RF24_PA_ERROR
    rf24_datarate_e:
      - RF24_1MBPS
      - RF24_2MBPS
      - RF24_250KBPS
    rf24_crclength_e:
      - RF24_CRC_DISABLED
      - RF24_CRC_8
      - RF24_CRC_16

parameters:
  - auto_ack!
  - payload_size
  - dynamic_payloads_enabled!
  - max_retry_count
  - retry_count
  - retry_delay
  - tx_power
  - datarate
  - channel

parameter_normalization:
  tx_power:
    unit: dBm
    enum:
      Nrf24l01::RF24_PA_MIN: 0
      Nrf24l01::RF24_PA_LOW: 6
      Nrf24l01::RF24_PA_HIGH: 12
      Nrf24l01::RF24_PA_MAX: 18
  datarate:
    unit: 'kbit/s'
    enum:
      Nrf24l01::RF24_1MBPS: 1000
      Nrf24l01::RF24_2MBPS: 2000
      Nrf24l01::RF24_250KBPS: 250
  retry_delay:
    unit: us
    formula: '250 * param + 250'

states:
  - UNINITIALIZED
  - POWEROFF
  - STANDBY1
  - TX
  - RX

transition:
  setup:
    src: [UNINITIALIZED, POWEROFF, STANDBY1]
    dst: STANDBY1
    set_param:
      'auto_ack!': 1
      'dynamic_payloads_enabled!': 0
      max_retry_count: 10
      retry_delay: 5
      datarate: 'Nrf24l01::RF24_1MBPS'
      tx_power: 'Nrf24l01::RF24_PA_MAX'
      channel: 76
  powerDown:
    src: [STANDBY1]
    dst: POWEROFF
  setAutoAck:
    src: [STANDBY1]
    dst: STANDBY1
    arguments:
      - name: enable
        values: [0, 1]
        parameter: 'auto_ack!'
  setPALevel:
    src: [STANDBY1]
    dst: STANDBY1
    arguments:
      - name: palevel
        values: ['Nrf24l01::RF24_PA_MIN', 'Nrf24l01::RF24_PA_LOW', 'Nrf24l01::RF24_PA_HIGH', 'Nrf24l01::RF24_PA_MAX']
        parameter: tx_power
  setDataRate:
    src: [STANDBY1]
    dst: STANDBY1
    arguments:
      - name: datarate
        values: ['Nrf24l01::RF24_1MBPS', 'Nrf24l01::RF24_2MBPS', 'Nrf24l01::RF24_250KBPS']
        parameter: datarate
  startListening:
    src: [STANDBY1]
    dst: RX
  stopListening:
    src: [RX]
    dst: STANDBY1
  setDynamicPayloads:
    src: [STANDBY1]
    dst: STANDBY1
    arguments:
      - name: enabled
        values: [0, 1]
        parameter: 'dynamic_payloads_enabled!'
  setRetries:
    src: [STANDBY1]
    dst: STANDBY1
    arguments:
      - name: delay
        values: [0, 5, 10, 15]
        parameter: retry_delay
      - name: count
        values: [0, 5, 10, 15]
        parameter: max_retry_count
  flushTx:
    src: [STANDBY1]
    dst: STANDBY1
  # only reports sensible values when auto_ack! == 1
  getObserveTx:
    src: [STANDBY1]
    dst: STANDBY1
    return_value:
      - parameter: retry_count
        formula: param & 0x0f
        apply_from: write
  write:
    src: [STANDBY1]
    dst: STANDBY1
    arguments:
      - name: buf
        values: ['"foo"', '"foo"', '"foofoofoo"', '"foofoofoo"', '"123456789012345678901234567890"', '"123456789012345678901234567890"']
      - name: len
        values: [3, 3, 9, 9, 30, 30]
        parameter: payload_size
      - name: await_ack
        values: [0, 1, 0, 1, 0, 1]
      - name: blocking
        values: [1, 1, 1, 1, 1, 1]
    argument_combination: zip
    return_value:
      - lol: nope
