From 84b65cb699ead52033844fb9355f426bdaef5e3e Mon Sep 17 00:00:00 2001 From: Alexsander Akers Date: Mon, 24 Jan 2022 19:06:54 -0500 Subject: Remove ADC_* defines in favor of hardware-specific mapping --- watch-library/hardware/watch/watch_adc.c | 20 +++++++++++++++++++- watch-library/shared/watch/watch_adc.h | 25 ++++--------------------- 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/watch-library/hardware/watch/watch_adc.c b/watch-library/hardware/watch/watch_adc.c index 5ba7abdf..32f06680 100644 --- a/watch-library/hardware/watch/watch_adc.c +++ b/watch-library/hardware/watch/watch_adc.c @@ -23,6 +23,7 @@ */ #include "watch_adc.h" +#include "driver_init.h" static void _watch_sync_adc(void) { while (ADC->SYNCBUSY.reg); @@ -138,13 +139,30 @@ void watch_set_analog_sampling_length(uint8_t cycles) { _watch_sync_adc(); } +static inline uint32_t _watch_adc_get_reference_voltage(const watch_adc_reference_voltage reference) { + switch (reference) { + case ADC_REFERENCE_INTREF: + return ADC_REFCTRL_REFSEL_INTREF_Val; + break; + case ADC_REFERENCE_VCC_DIV1POINT6: + return ADC_REFCTRL_REFSEL_INTVCC0_Val; + break; + case ADC_REFERENCE_VCC_DIV2: + return ADC_REFCTRL_REFSEL_INTVCC1_Val; + break; + case ADC_REFERENCE_VCC: + return ADC_REFCTRL_REFSEL_INTVCC2_Val; + break; + } +} + void watch_set_analog_reference_voltage(watch_adc_reference_voltage reference) { ADC->CTRLA.bit.ENABLE = 0; if (reference == ADC_REFERENCE_INTREF) SUPC->VREF.bit.VREFOE = 1; else SUPC->VREF.bit.VREFOE = 0; - ADC->REFCTRL.bit.REFSEL = reference; + ADC->REFCTRL.bit.REFSEL = _watch_adc_get_reference_voltage(reference); ADC->CTRLA.bit.ENABLE = 1; _watch_sync_adc(); // throw away one measurement after reference change (the channel doesn't matter). diff --git a/watch-library/shared/watch/watch_adc.h b/watch-library/shared/watch/watch_adc.h index d4c8586d..ea4fa9e3 100644 --- a/watch-library/shared/watch/watch_adc.h +++ b/watch-library/shared/watch/watch_adc.h @@ -27,23 +27,6 @@ #include "watch.h" -// matches adc.h -#ifndef ADC_REFCTRL_REFSEL_INTREF_Val -#define ADC_REFCTRL_REFSEL_INTREF_Val 0x0 -#endif - -#ifndef ADC_REFCTRL_REFSEL_INTVCC0_Val -#define ADC_REFCTRL_REFSEL_INTVCC0_Val 0x1 -#endif - -#ifndef ADC_REFCTRL_REFSEL_INTVCC1_Val -#define ADC_REFCTRL_REFSEL_INTVCC1_Val 0x2 -#endif - -#ifndef ADC_REFCTRL_REFSEL_INTVCC2_Val -#define ADC_REFCTRL_REFSEL_INTVCC2_Val 0x5 -#endif - /** @addtogroup adc Analog Input * @brief This section covers functions related to the SAM L22's analog-to-digital converter, * as well as configuring and reading values from the five analog-capable pins on the @@ -112,10 +95,10 @@ void watch_set_analog_num_samples(uint16_t samples); void watch_set_analog_sampling_length(uint8_t cycles); typedef enum { - ADC_REFERENCE_INTREF = ADC_REFCTRL_REFSEL_INTREF_Val, - ADC_REFERENCE_VCC_DIV1POINT6 = ADC_REFCTRL_REFSEL_INTVCC0_Val, - ADC_REFERENCE_VCC_DIV2 = ADC_REFCTRL_REFSEL_INTVCC1_Val, - ADC_REFERENCE_VCC = ADC_REFCTRL_REFSEL_INTVCC2_Val, + ADC_REFERENCE_INTREF = 0, + ADC_REFERENCE_VCC_DIV1POINT6, + ADC_REFERENCE_VCC_DIV2, + ADC_REFERENCE_VCC, } watch_adc_reference_voltage; -- cgit v1.2.3 From c313ea5911fbdd49d49481e7257fb9a32f7b1c46 Mon Sep 17 00:00:00 2001 From: Alexsander Akers Date: Tue, 25 Jan 2022 18:09:56 -0500 Subject: Add GitHub Workflow job to build and archive simulator --- .github/workflows/build.yml | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 93928721..7439d32e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -28,3 +28,31 @@ jobs: with: name: watch.uf2 path: movement/make/build/watch.uf2 + + build-simulator: + container: + image: emscripten/emsdk + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Compile starter-project app + run: emmake make + working-directory: 'apps/starter-project' + - name: Compile accelerometer-test app + run: emmake make + working-directory: 'apps/accelerometer-test' + - name: Compile movement + run: emmake make + working-directory: 'movement/make' + - name: Archive simulator build + if: ${{ matrix.target == 'simulator' }} + working-directory: 'movement/make/build' + run: | + cp watch.html index.html + tar -czf simulator.tar.gz index.html watch.wasm watch.js + - name: Upload simulator build + uses: actions/upload-artifact@v2 + with: + name: simulator.tar.gz + path: movement/make/build/simulator.tar.gz -- cgit v1.2.3 From b57c579c69a3b974ba2891bde890f5c9fa8f9dfc Mon Sep 17 00:00:00 2001 From: Alexsander Akers Date: Tue, 25 Jan 2022 18:16:31 -0500 Subject: Don't compile starter-project or accelerometer-test These apps have not been tested in the simulator runtime yet. --- .github/workflows/build.yml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7439d32e..7be0508c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -36,12 +36,6 @@ jobs: steps: - name: Checkout uses: actions/checkout@v2 - - name: Compile starter-project app - run: emmake make - working-directory: 'apps/starter-project' - - name: Compile accelerometer-test app - run: emmake make - working-directory: 'apps/accelerometer-test' - name: Compile movement run: emmake make working-directory: 'movement/make' -- cgit v1.2.3 From 2f1458bd46c4fa5843e8924068def16482815376 Mon Sep 17 00:00:00 2001 From: Alexsander Akers Date: Tue, 25 Jan 2022 18:17:51 -0500 Subject: Remove dangling `if` condition --- .github/workflows/build.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7be0508c..4b1f6fab 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -40,7 +40,6 @@ jobs: run: emmake make working-directory: 'movement/make' - name: Archive simulator build - if: ${{ matrix.target == 'simulator' }} working-directory: 'movement/make/build' run: | cp watch.html index.html -- cgit v1.2.3 From 23610430b31bce8e147080d9a9d660b98e28b418 Mon Sep 17 00:00:00 2001 From: David Keck Date: Wed, 26 Jan 2022 18:59:48 -0500 Subject: Added rough draft of watch_face script to generate custom watch faces from template. Corrected template file's missing includes and incorrect memset placeholder. --- movement/template/template.c | 4 ++- movement/template/watch_face.py | 73 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 movement/template/watch_face.py diff --git a/movement/template/template.c b/movement/template/template.c index 3f60be97..34c6dbf5 100644 --- a/movement/template/template.c +++ b/movement/template/template.c @@ -22,13 +22,15 @@ * SOFTWARE. */ +#include +#include #include "<#watch_face_name#>_face.h" void <#watch_face_name#>_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr) { (void) settings; if (*context_ptr == NULL) { *context_ptr = malloc(sizeof(<#watch_face_name#>_state_t)); - memset(*context_ptr, 0, sizeof(<#watch_face_name#>)); + memset(*context_ptr, 0, sizeof(<#watch_face_name#>_state_t)); // Do any one-time tasks in here; the inside of this conditional happens only at boot. } // Do any pin or peripheral setup here; this will be called whenever the watch wakes from deep sleep. diff --git a/movement/template/watch_face.py b/movement/template/watch_face.py new file mode 100644 index 00000000..673e1f19 --- /dev/null +++ b/movement/template/watch_face.py @@ -0,0 +1,73 @@ +import os +import re +import argparse + + +MAKEFILE_INDICATOR = "# New watch faces go above this line.\n" +INCLUDE_INDICATOR = "// New includes go above this line.\n" + + +def replace_placeholders(contents, args): + modified_contents = contents.replace("<#WATCH_FACE_NAME#>", args.watch_face_name.upper()) + modified_contents = modified_contents.replace("<#watch_face_name#>", args.watch_face_name) + if args.author_name: + modified_contents = modified_contents.replace("<#author_name#>", " ".join(args.author_name)) + if args.year: + modified_contents = modified_contents.replace("<#year#>", args.year) + + return modified_contents + + +def write_output_file(args, file_type, output_dir): + with open(f"template.{file_type}", 'r') as file_template: + file_contents = file_template.read() + modified_template = replace_placeholders(file_contents, args) + file_path = f"{output_dir}{args.watch_face_name}_face.{file_type}" + if not os.path.exists(file_path): + with open(file_path, 'w') as output_file: + output_file.write(modified_template) + else: + print(f"Generation failed: the watch face \"{args.watch_face_name}\" already exists at {file_path}. Unable to generate new files. Exiting...") + exit(0) + + +def write_include_file(file_path, file_type, indicator_line, line_to_insert): + with open(file_path, 'r+') as include_file: + include_contents = include_file.readlines() + if line_to_insert in include_contents: + print(f"Generation failed: {file_path} already has an entry for {line_to_insert.strip()}. Unable to generate new files. Exiting...") + exit(0) + new_face_index = include_contents.index(indicator_line) + include_contents.insert(new_face_index, line_to_insert) + include_file.seek(0) + include_file.writelines(include_contents) + + +def main(): + parser = argparse.ArgumentParser(description="Create a new watch face.") + parser.add_argument("watch_face_type", metavar="face_type", type=str, choices=["complication", "clock"], help="The type of watch face to create, either \"complication\" or \"clock\"") + parser.add_argument("watch_face_name", metavar="face_name", type=str, help="The name of the watch face") + parser.add_argument("--author_name", metavar="author_name", type=str, nargs='*', help="The name of the author") + parser.add_argument("--year", metavar="year", type=str, help="The copyright year") + + args = parser.parse_args() + + name_valid = re.fullmatch(r'[a-zA-Z_][a-zA-Z0-9_]*', args.watch_face_name) + if name_valid == None: + print(f"Generation failed: {args.watch_face_name} is not a valid C variable name. Exiting...") + exit(0) + + line_to_insert = f"#include \"{args.watch_face_name}_face.h\"\n" + write_include_file(f"..{os.sep}movement_faces.h", "h", INCLUDE_INDICATOR, line_to_insert) + + line_to_insert = f" ..{os.sep}watch_faces{os.sep}{args.watch_face_type}{os.sep}{args.watch_face_name}_face.c \\\n" + write_include_file(f"..{os.sep}make{os.sep}Makefile", "c", MAKEFILE_INDICATOR, line_to_insert) + + output_dir = f"..{os.sep}watch_faces{os.sep}{args.watch_face_type}{os.sep}" + write_output_file(args, "h", output_dir) + write_output_file(args, "c", output_dir) + + +if __name__ == "__main__": + main() + -- cgit v1.2.3 From d58908517b271499e5c0920030907fbd70983bfb Mon Sep 17 00:00:00 2001 From: David Keck Date: Wed, 26 Jan 2022 19:07:51 -0500 Subject: Added license info to script --- movement/template/watch_face.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/movement/template/watch_face.py b/movement/template/watch_face.py index 673e1f19..71b29301 100644 --- a/movement/template/watch_face.py +++ b/movement/template/watch_face.py @@ -1,3 +1,25 @@ +# MIT License +# +# Copyright (c) 2022 David Keck +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + import os import re import argparse -- cgit v1.2.3 From cc2696c71a3cfc0e76f5daeafbde20cdc8790324 Mon Sep 17 00:00:00 2001 From: David Keck Date: Wed, 26 Jan 2022 19:12:12 -0500 Subject: added missing newlines to template files --- movement/template/template.c | 1 + movement/template/template.h | 1 + 2 files changed, 2 insertions(+) diff --git a/movement/template/template.c b/movement/template/template.c index 34c6dbf5..8a77d6c3 100644 --- a/movement/template/template.c +++ b/movement/template/template.c @@ -89,3 +89,4 @@ void <#watch_face_name#>_face_resign(movement_settings_t *settings, void *contex // handle any cleanup before your watch face goes off-screen. } + diff --git a/movement/template/template.h b/movement/template/template.h index 29f66346..8c1b3126 100644 --- a/movement/template/template.h +++ b/movement/template/template.h @@ -46,3 +46,4 @@ void <#watch_face_name#>_face_resign(movement_settings_t *settings, void *contex }) #endif // <#WATCH_FACE_NAME#>_FACE_H_ + -- cgit v1.2.3 From c130f13bb802c91d65c7ad96a49976678e76ac2b Mon Sep 17 00:00:00 2001 From: David Keck Date: Wed, 26 Jan 2022 19:15:16 -0500 Subject: minor typo fix --- movement/template/template.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/movement/template/template.c b/movement/template/template.c index 8a77d6c3..c9c174b6 100644 --- a/movement/template/template.c +++ b/movement/template/template.c @@ -78,7 +78,7 @@ bool <#watch_face_name#>_face_loop(movement_event_t event, movement_settings_t * break; } - // return true if the watch can enter standby mode. If you are PWM'ing an LED or buzzing the buzzer nere, + // return true if the watch can enter standby mode. If you are PWM'ing an LED or buzzing the buzzer here, // you should return false since the PWM driver does not operate in standby mode. return true; } -- cgit v1.2.3 From 5d5e5b125a383174f1891d37498415cc10fe84fe Mon Sep 17 00:00:00 2001 From: Joey Castillo Date: Wed, 26 Jan 2022 20:31:04 -0500 Subject: watch face script: autopopulate year --- movement/template/watch_face.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/movement/template/watch_face.py b/movement/template/watch_face.py index 71b29301..85a0f8b2 100644 --- a/movement/template/watch_face.py +++ b/movement/template/watch_face.py @@ -22,6 +22,7 @@ import os import re +import datetime import argparse @@ -32,10 +33,9 @@ INCLUDE_INDICATOR = "// New includes go above this line.\n" def replace_placeholders(contents, args): modified_contents = contents.replace("<#WATCH_FACE_NAME#>", args.watch_face_name.upper()) modified_contents = modified_contents.replace("<#watch_face_name#>", args.watch_face_name) + modified_contents = modified_contents.replace("<#year#>", datetime.datetime.now().strftime("%Y")) if args.author_name: modified_contents = modified_contents.replace("<#author_name#>", " ".join(args.author_name)) - if args.year: - modified_contents = modified_contents.replace("<#year#>", args.year) return modified_contents @@ -70,7 +70,6 @@ def main(): parser.add_argument("watch_face_type", metavar="face_type", type=str, choices=["complication", "clock"], help="The type of watch face to create, either \"complication\" or \"clock\"") parser.add_argument("watch_face_name", metavar="face_name", type=str, help="The name of the watch face") parser.add_argument("--author_name", metavar="author_name", type=str, nargs='*', help="The name of the author") - parser.add_argument("--year", metavar="year", type=str, help="The copyright year") args = parser.parse_args() -- cgit v1.2.3 href='#n417'>417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880