forked from micropython/micropython
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for RP2040 GPIN/GPOUT (clkio) #9009
Open
tinylabs
wants to merge
11
commits into
adafruit:main
Choose a base branch
from
tinylabs:rp2-clkio-support
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
d2b1b74
Add support for RP2040 GPIN/GPOUT (clkio)
tinylabs 3b1a31a
Run make translate, remove whitespace
tinylabs 2f31860
Fix code formatting
tinylabs 128b8c4
Rename clkio to rp2clock
tinylabs c60fa3d
Update class names
tinylabs a5dd74c
Update formatting
tinylabs ee36308
Rebuild translations
tinylabs bb6a09e
Move to enum macro, make requested changes
tinylabs 670df5c
Fix docs
tinylabs d35cda7
Update docs
tinylabs 852814b
Fix doc formatting
tinylabs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,179 @@ | ||
/* | ||
* This file is part of the Micro Python project, http://micropython.org/ | ||
* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2024 Elliot Buller | ||
* | ||
* 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. | ||
*/ | ||
|
||
#include "py/runtime.h" | ||
#include "supervisor/shared/translate/translate.h" | ||
#include "bindings/clkio/ClkAuxSrc.h" | ||
|
||
//| class ClkAuxSrc: | ||
//| """Defines the input clock for GPOUT on RP2040""" | ||
//| | ||
//| def __init__(self) -> None: | ||
//| """Enum-like class to define the clock src.""" | ||
//| | ||
const mp_obj_type_t clkio_clkauxsrc_type; | ||
|
||
const clkio_clkauxsrc_obj_t clkio_clkauxsrc_pll_sys_obj = { | ||
{ &clkio_clkauxsrc_type }, | ||
}; | ||
const clkio_clkauxsrc_obj_t clkio_clkauxsrc_gpin0_obj = { | ||
{ &clkio_clkauxsrc_type }, | ||
}; | ||
const clkio_clkauxsrc_obj_t clkio_clkauxsrc_gpin1_obj = { | ||
{ &clkio_clkauxsrc_type }, | ||
}; | ||
const clkio_clkauxsrc_obj_t clkio_clkauxsrc_pll_usb_obj = { | ||
{ &clkio_clkauxsrc_type }, | ||
}; | ||
const clkio_clkauxsrc_obj_t clkio_clkauxsrc_pll_rosc_obj = { | ||
{ &clkio_clkauxsrc_type }, | ||
}; | ||
const clkio_clkauxsrc_obj_t clkio_clkauxsrc_pll_xosc_obj = { | ||
{ &clkio_clkauxsrc_type }, | ||
}; | ||
const clkio_clkauxsrc_obj_t clkio_clkauxsrc_sys_obj = { | ||
{ &clkio_clkauxsrc_type }, | ||
}; | ||
const clkio_clkauxsrc_obj_t clkio_clkauxsrc_usb_obj = { | ||
{ &clkio_clkauxsrc_type }, | ||
}; | ||
const clkio_clkauxsrc_obj_t clkio_clkauxsrc_adc_obj = { | ||
{ &clkio_clkauxsrc_type }, | ||
}; | ||
const clkio_clkauxsrc_obj_t clkio_clkauxsrc_rtc_obj = { | ||
{ &clkio_clkauxsrc_type }, | ||
}; | ||
const clkio_clkauxsrc_obj_t clkio_clkauxsrc_ref_obj = { | ||
{ &clkio_clkauxsrc_type }, | ||
}; | ||
|
||
|
||
STATIC const mp_rom_map_elem_t clkio_clkauxsrc_locals_dict_table[] = { | ||
{ MP_ROM_QSTR(MP_QSTR_PLL_SYS), MP_ROM_PTR(&clkio_clkauxsrc_pll_sys_obj) }, | ||
{ MP_ROM_QSTR(MP_QSTR_GPIN0), MP_ROM_PTR(&clkio_clkauxsrc_gpin0_obj) }, | ||
{ MP_ROM_QSTR(MP_QSTR_GPIN1), MP_ROM_PTR(&clkio_clkauxsrc_gpin1_obj) }, | ||
{ MP_ROM_QSTR(MP_QSTR_PLL_USB), MP_ROM_PTR(&clkio_clkauxsrc_pll_usb_obj) }, | ||
{ MP_ROM_QSTR(MP_QSTR_PLL_ROSC), MP_ROM_PTR(&clkio_clkauxsrc_pll_rosc_obj) }, | ||
{ MP_ROM_QSTR(MP_QSTR_PLL_XOSC), MP_ROM_PTR(&clkio_clkauxsrc_pll_xosc_obj) }, | ||
{ MP_ROM_QSTR(MP_QSTR_SYS), MP_ROM_PTR(&clkio_clkauxsrc_sys_obj) }, | ||
{ MP_ROM_QSTR(MP_QSTR_USB), MP_ROM_PTR(&clkio_clkauxsrc_usb_obj) }, | ||
{ MP_ROM_QSTR(MP_QSTR_ADC), MP_ROM_PTR(&clkio_clkauxsrc_adc_obj) }, | ||
{ MP_ROM_QSTR(MP_QSTR_RTC), MP_ROM_PTR(&clkio_clkauxsrc_rtc_obj) }, | ||
{ MP_ROM_QSTR(MP_QSTR_REF), MP_ROM_PTR(&clkio_clkauxsrc_ref_obj) }, | ||
}; | ||
STATIC MP_DEFINE_CONST_DICT(clkio_clkauxsrc_locals_dict, clkio_clkauxsrc_locals_dict_table); | ||
|
||
STATIC void clkio_clkauxsrc_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { | ||
qstr clk = MP_QSTR_INVALID; | ||
if (self_in == MP_ROM_PTR(&clkio_clkauxsrc_pll_sys_obj)) { | ||
clk = MP_QSTR_PLL_SYS; | ||
} else if (self_in == MP_ROM_PTR(&clkio_clkauxsrc_gpin0_obj)) { | ||
clk = MP_QSTR_GPIN0; | ||
} else if (self_in == MP_ROM_PTR(&clkio_clkauxsrc_gpin1_obj)) { | ||
clk = MP_QSTR_GPIN1; | ||
} else if (self_in == MP_ROM_PTR(&clkio_clkauxsrc_pll_usb_obj)) { | ||
clk = MP_QSTR_PLL_USB; | ||
} else if (self_in == MP_ROM_PTR(&clkio_clkauxsrc_pll_rosc_obj)) { | ||
clk = MP_QSTR_PLL_ROSC; | ||
} else if (self_in == MP_ROM_PTR(&clkio_clkauxsrc_pll_xosc_obj)) { | ||
clk = MP_QSTR_PLL_XOSC; | ||
} else if (self_in == MP_ROM_PTR(&clkio_clkauxsrc_sys_obj)) { | ||
clk = MP_QSTR_SYS; | ||
} else if (self_in == MP_ROM_PTR(&clkio_clkauxsrc_usb_obj)) { | ||
clk = MP_QSTR_USB; | ||
} else if (self_in == MP_ROM_PTR(&clkio_clkauxsrc_adc_obj)) { | ||
clk = MP_QSTR_ADC; | ||
} else if (self_in == MP_ROM_PTR(&clkio_clkauxsrc_rtc_obj)) { | ||
clk = MP_QSTR_RTC; | ||
} else if (self_in == MP_ROM_PTR(&clkio_clkauxsrc_ref_obj)) { | ||
clk = MP_QSTR_REF; | ||
} | ||
mp_printf(print, "%q.%q.%q", MP_QSTR_clkio, MP_QSTR_ClkAuxSrc, clk); | ||
} | ||
|
||
MP_DEFINE_CONST_OBJ_TYPE( | ||
clkio_clkauxsrc_type, | ||
MP_QSTR_ClkAuxSrc, | ||
MP_TYPE_FLAG_NONE, | ||
print, clkio_clkauxsrc_print, | ||
locals_dict, &clkio_clkauxsrc_locals_dict | ||
); | ||
|
||
mp_obj_t clkauxsrc_get_obj(clkio_clkauxsrc_t type) { | ||
if (type == CLKAUXSRC_PLL_SYS) { | ||
return MP_OBJ_FROM_PTR(&clkio_clkauxsrc_pll_sys_obj); | ||
} else if (type == CLKAUXSRC_GPIN0) { | ||
return MP_OBJ_FROM_PTR(&clkio_clkauxsrc_gpin0_obj); | ||
} else if (type == CLKAUXSRC_GPIN1) { | ||
return MP_OBJ_FROM_PTR(&clkio_clkauxsrc_gpin1_obj); | ||
} else if (type == CLKAUXSRC_PLL_USB) { | ||
return MP_OBJ_FROM_PTR(&clkio_clkauxsrc_pll_usb_obj); | ||
} else if (type == CLKAUXSRC_PLL_ROSC) { | ||
return MP_OBJ_FROM_PTR(&clkio_clkauxsrc_pll_rosc_obj); | ||
} else if (type == CLKAUXSRC_PLL_XOSC) { | ||
return MP_OBJ_FROM_PTR(&clkio_clkauxsrc_pll_xosc_obj); | ||
} else if (type == CLKAUXSRC_SYS) { | ||
return MP_OBJ_FROM_PTR(&clkio_clkauxsrc_sys_obj); | ||
} else if (type == CLKAUXSRC_USB) { | ||
return MP_OBJ_FROM_PTR(&clkio_clkauxsrc_usb_obj); | ||
} else if (type == CLKAUXSRC_ADC) { | ||
return MP_OBJ_FROM_PTR(&clkio_clkauxsrc_adc_obj); | ||
} else if (type == CLKAUXSRC_RTC) { | ||
return MP_OBJ_FROM_PTR(&clkio_clkauxsrc_rtc_obj); | ||
} else if (type == CLKAUXSRC_REF) { | ||
return MP_OBJ_FROM_PTR(&clkio_clkauxsrc_ref_obj); | ||
} else { | ||
return MP_ROM_NONE; | ||
} | ||
} | ||
clkio_clkauxsrc_t validate_clkauxsrc(mp_rom_obj_t obj, qstr arg_name) { | ||
if (obj == MP_ROM_PTR(&clkio_clkauxsrc_pll_sys_obj)) { | ||
return CLKAUXSRC_PLL_SYS; | ||
} else if (obj == MP_ROM_PTR(&clkio_clkauxsrc_gpin0_obj)) { | ||
return CLKAUXSRC_GPIN0; | ||
} else if (obj == MP_ROM_PTR(&clkio_clkauxsrc_gpin1_obj)) { | ||
return CLKAUXSRC_GPIN1; | ||
} else if (obj == MP_ROM_PTR(&clkio_clkauxsrc_pll_usb_obj)) { | ||
return CLKAUXSRC_PLL_USB; | ||
} else if (obj == MP_ROM_PTR(&clkio_clkauxsrc_pll_rosc_obj)) { | ||
return CLKAUXSRC_PLL_ROSC; | ||
} else if (obj == MP_ROM_PTR(&clkio_clkauxsrc_pll_xosc_obj)) { | ||
return CLKAUXSRC_PLL_XOSC; | ||
} else if (obj == MP_ROM_PTR(&clkio_clkauxsrc_sys_obj)) { | ||
return CLKAUXSRC_SYS; | ||
} else if (obj == MP_ROM_PTR(&clkio_clkauxsrc_usb_obj)) { | ||
return CLKAUXSRC_USB; | ||
} else if (obj == MP_ROM_PTR(&clkio_clkauxsrc_adc_obj)) { | ||
return CLKAUXSRC_ADC; | ||
} else if (obj == MP_ROM_PTR(&clkio_clkauxsrc_rtc_obj)) { | ||
return CLKAUXSRC_RTC; | ||
} else if (obj == MP_ROM_PTR(&clkio_clkauxsrc_ref_obj)) { | ||
return CLKAUXSRC_REF; | ||
} else if (obj == MP_ROM_NONE) { | ||
return CLKAUXSRC_NONE; | ||
} | ||
mp_raise_TypeError_varg(MP_ERROR_TEXT("%q must be of type %q or %q, not %q"), arg_name, MP_QSTR_ClkAuxSrc, MP_QSTR_None, mp_obj_get_type(obj)->name); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* This file is part of the Micro Python project, http://micropython.org/ | ||
* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2024 Elliot Buller | ||
* | ||
* 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. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "py/obj.h" | ||
|
||
// Output sources | ||
typedef enum _clkio_clkauxsrc_t { | ||
CLKAUXSRC_PLL_SYS = 0, | ||
CLKAUXSRC_GPIN0 = 1, | ||
CLKAUXSRC_GPIN1 = 2, | ||
CLKAUXSRC_PLL_USB = 3, | ||
CLKAUXSRC_PLL_ROSC = 4, | ||
CLKAUXSRC_PLL_XOSC = 5, | ||
CLKAUXSRC_SYS = 6, | ||
CLKAUXSRC_USB = 7, | ||
CLKAUXSRC_ADC = 8, | ||
CLKAUXSRC_RTC = 9, | ||
CLKAUXSRC_REF = 10, | ||
CLKAUXSRC_NONE = 11, | ||
} clkio_clkauxsrc_t; | ||
|
||
extern const mp_obj_type_t clkio_clkauxsrc_type; | ||
|
||
typedef struct { | ||
mp_obj_base_t base; | ||
} clkio_clkauxsrc_obj_t; | ||
|
||
extern const clkio_clkauxsrc_obj_t clkio_clkauxsrc_pll_sys_obj; | ||
extern const clkio_clkauxsrc_obj_t clkio_clkauxsrc_gpin0_obj; | ||
extern const clkio_clkauxsrc_obj_t clkio_clkauxsrc_gpin1_obj; | ||
extern const clkio_clkauxsrc_obj_t clkio_clkauxsrc_pll_usb_obj; | ||
extern const clkio_clkauxsrc_obj_t clkio_clkauxsrc_pll_rosc_obj; | ||
extern const clkio_clkauxsrc_obj_t clkio_clkauxsrc_pll_xosc_obj; | ||
extern const clkio_clkauxsrc_obj_t clkio_clkauxsrc_sys_obj; | ||
extern const clkio_clkauxsrc_obj_t clkio_clkauxsrc_usb_obj; | ||
extern const clkio_clkauxsrc_obj_t clkio_clkauxsrc_adc_obj; | ||
extern const clkio_clkauxsrc_obj_t clkio_clkauxsrc_rtc_obj; | ||
extern const clkio_clkauxsrc_obj_t clkio_clkauxsrc_ref_obj; | ||
|
||
clkio_clkauxsrc_t validate_clkauxsrc(mp_rom_obj_t obj, qstr arg_name); | ||
mp_obj_t clkauxsrc_get_obj(clkio_clkauxsrc_t type); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please try to reuse messages in this file instead of adding new ones. That way there is less to translate and less to store in the firmware.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tried my best to combine them on latest commits.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just curious, do all translations end up in every build regardless of the modules compiled in? I just assumed that these would only be pulled in when CIRCUITPY_RP2CLOCK=1. I can make the messages more generic to reuse them but we'd lose some information.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only translations for enabled modules are included. I assume we'll have RP2CLOCK enabled for all RP2040 boards where it'll fit. Striking the generic vs specific balance can be tricky.