keypadgen.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #!/usr/bin/env python3
  2. # Copyright (C) 2018 RDA Technologies Limited and/or its affiliates("RDA").
  3. # All rights reserved.
  4. #
  5. # This software is supplied "AS IS" without any warranties.
  6. # RDA assumes no responsibility or liability for the use of the software,
  7. # conveys no license or title under any patent, copyright, or mask work
  8. # right to the product. RDA reserves the right to make changes in the
  9. # software without notification. RDA also make no representation or
  10. # warranty that such application will be suitable for the specified use
  11. # without further testing or modification.
  12. import argparse
  13. import csv
  14. DESCRIPTION = '''
  15. Generate keypad map source file from csv
  16. '''
  17. def main():
  18. parser = argparse.ArgumentParser(description=DESCRIPTION)
  19. parser.add_argument("csv", help="csv file for keypad map")
  20. parser.add_argument("keypaddef", nargs="?", default='drv_keypad_def.h')
  21. args = parser.parse_args()
  22. pins = []
  23. with open(args.csv, "r") as fh:
  24. pinmap = csv.reader(fh)
  25. key_row = -1
  26. for col in pinmap:
  27. if not col[0]:
  28. continue
  29. key_row += 1
  30. key_col = -1
  31. for pin in col[1:]:
  32. key_col += 1
  33. if not pin:
  34. continue
  35. pins.append('{SCAN_ROW_COL(%d, %d), %s}' %
  36. (key_row, key_col, pin))
  37. with open(args.keypaddef, "w") as fh:
  38. fh.write('// Auto generated. Don\'t edit it manually!\n\n')
  39. fh.write('static const drvKeypadScanMap_t gKeyMatrix[] =\n{\n ')
  40. fh.write(',\n '.join(pins))
  41. fh.write(",\n};\n")
  42. if __name__ == "__main__":
  43. main()