; ***************************************************************************
; copyright   : (C) 2023 by Martin Preuss
; email       : martin@libchipcard.de
;
; ***************************************************************************
; * This file is part of the project "AqHome".                              *
; * Please see toplevel file COPYING of that project for license details.   *
; ***************************************************************************




; ***************************************************************************
; code

.cseg


; ---------------------------------------------------------------------------
; Enqueue a DEVICE packet.
;
; IN:
; - R16: destination address
; - X  : buffer to write to
; OUT:
; - nothing
; REGS: R3, R4, R16, R17, R18, X (R19, R20, R21)

CPRO_WriteDevice:
  ldi r17, COM2_PAYLOAD_FLAGS_UID | (6<<COM2_PAYLOAD_FLAGS_SHIFT_NUM)
  ldi r18, CPRO_CMD_DEVICE
  push xh
    push xl
      rcall COM2_BeginMsgWithVariablePayload    ; (R3, R4, R16, R17, R18, R19, R20, R21, X)
      lds r17, firmwareType
      st X+, r17                             ; 6: firmware type low
      lds r17, firmwareType+1
      st X+, r17                             ; 7: firmware type high
      lds r17, firmwareVersion
      st X+, r17                             ; 8: version low
      lds r17, firmwareVersion+1
      st X+, r17                             ; 9: version high
      lds r17, firmwareModules
      st X+, r17                             ; 10: modules mask low
      lds r17, firmwareModules+1
      st X+, r17                             ; 11: modules mask low
    pop xl
  pop xh
  rcall com2CalcAndAddChecksumByte             ; (R16, R17, R18, R19, X)
  ret



