{"action":"created","issue":{"url":"https://api.github.com/repos/micropython/micropython/issues/1405","labels_url":"https://api.github.com/repos/micropython/micropython/issues/1405/labels{/name}","comments_url":"https://api.github.com/repos/micropython/micropython/issues/1405/comments","events_url":"https://api.github.com/repos/micropython/micropython/issues/1405/events","html_url":"https://github.com/micropython/micropython/issues/1405","id":98570011,"number":1405,"title":"Inconsistent pin behaviour","user":{"login":"dhylands","id":127500,"avatar_url":"https://avatars.githubusercontent.com/u/127500?v=3","gravatar_id":"","url":"https://api.github.com/users/dhylands","html_url":"https://github.com/dhylands","followers_url":"https://api.github.com/users/dhylands/followers","following_url":"https://api.github.com/users/dhylands/following{/other_user}","gists_url":"https://api.github.com/users/dhylands/gists{/gist_id}","starred_url":"https://api.github.com/users/dhylands/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dhylands/subscriptions","organizations_url":"https://api.github.com/users/dhylands/orgs","repos_url":"https://api.github.com/users/dhylands/repos","events_url":"https://api.github.com/users/dhylands/events{/privacy}","received_events_url":"https://api.github.com/users/dhylands/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":14,"created_at":"2015-08-02T00:02:34Z","updated_at":"2015-08-03T01:29:18Z","closed_at":null,"body":"I've run into an issue which I throught I would bring up, and see how to best go about solving it.\r\nIf I do:\r\n```python\r\npin = pyb.Pin('J12', pyb.Pin.IN)\r\n```\r\nThen I get a pin which has been run through the Pin type's make_new and init_helper function. If I do:\r\n```python\r\npin = pyb.Pin('J12')\r\n```\r\nThen I get a pin which has been run through the Pin type's make_new function, but not the init helper function. If I then try to query the pin's value, it always returns zero because the clock for that port hasn't been initialized. I can move the clock initialization to the make_new function to get around this.\r\n\r\nHowever, I can also get a pin via:\r\n```python\r\npin = pyb.Pin.cpu.J12\r\n```\r\nand I get a pin from the dictionary in flash that hasn't been run through make_new and have the same problem. I can query the pin:\r\n```python\r\n>>> pyb.Pin.cpu.J12\r\nPin(Pin.cpu.J12, mode=Pin.IN)\r\n>>> pyb.Pin.cpu.J12.value()\r\n0\r\n>>> pin = pyb.Pin('J12', pyb.Pin.IN)\r\n>>> pyb.Pin.cpu.J12.value()\r\n1\r\n```\r\nFor ports A-D, you can do the above and the first call to value() will return 1 because the clock is enabled.\r\n\r\nMy question is, do we want to resolve this inconsistency?\r\nShould we consider raising an error on a pin that hasn't been initialized?\r\nOr should we enable the clock?\r\n\r\nRight now, when you ask for pyb.Pin.cpu.J12 you're getting a pin from a local_dict:\r\nhttps://github.com/micropython/micropython/blob/master/stmhal/pin_named_pins.c#L43\r\n\r\nBy changing this to an attr and we could have the gpio clock enabled. Or we could throw an error if init hasn't been called yet, or we could do nothing.\r\n\r\nSo I just thought I'd throw this out for discussion."},"comment":{"url":"https://api.github.com/repos/micropython/micropython/issues/comments/127094933","html_url":"https://github.com/micropython/micropython/issues/1405#issuecomment-127094933","issue_url":"https://api.github.com/repos/micropython/micropython/issues/1405","id":127094933,"user":{"login":"dhylands","id":127500,"avatar_url":"https://avatars.githubusercontent.com/u/127500?v=3","gravatar_id":"","url":"https://api.github.com/users/dhylands","html_url":"https://github.com/dhylands","followers_url":"https://api.github.com/users/dhylands/followers","following_url":"https://api.github.com/users/dhylands/following{/other_user}","gists_url":"https://api.github.com/users/dhylands/gists{/gist_id}","starred_url":"https://api.github.com/users/dhylands/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dhylands/subscriptions","organizations_url":"https://api.github.com/users/dhylands/orgs","repos_url":"https://api.github.com/users/dhylands/repos","events_url":"https://api.github.com/users/dhylands/events{/privacy}","received_events_url":"https://api.github.com/users/dhylands/received_events","type":"User","site_admin":false},"created_at":"2015-08-03T01:29:18Z","updated_at":"2015-08-03T01:29:18Z","body":"Perhaps the best thing to do is to clarify the various examples in the documentation."}}