Code Monkey home page Code Monkey logo

micropython-mcp7940's People

Contributors

mattytrentini avatar

Stargazers

 avatar

Watchers

 avatar

micropython-mcp7940's Issues

Add data storage

The MCP7940 has 64 bytes of onboard storage that is retained when the RTC is powered by a battery.

Seems like this would be best implemented with a slice operator:

mcp.data[0:10] = range(10) # Set first ten bytes to 1..10
fourth = mcp.data[4] # Read fourth byte

Add Calibration feature

The MCP supports calibration of the oscillator. We need to expose the fields to allow the calibration to occur.

Include leap year when setting the time

Although there's an is_leap_year function - and it's been tested - it's not currently used.

It should be used when setting the time on the MCP so the RTC knows how to increment time as it rolls through February.

is_leap_year function no ```self``` parameter

Hi, I created a fork of your repo (by using the tinyPICO fork of it that is).
Beside the fact that the file mcp7940.py has an is_leap_year function, I see that this function is only mentioned in the commentary but nowhere called from inside the class. Since I decided to use the is_leap_year function, which I needed for an added yearday function, I discovered that the function defintion of the is_leap_year function has no self defined as first parameter, like I did:
def is_leap_year(self, year):

Without self the function could be called with e.g.: MCP7940.is_leap_year(current_year)

I see that you did this also with the functions bcd_to_int(bcd): and def int_to_bcd(i): and call these from within the same class with t = [(MCP7940.int_to_bcd(reg) & filt) for reg, filt in zip(time_reg, reg_filter)] in function alarm1.

and with t = [MCP7940.bcd_to_int(reg & filt) for reg, filt in zip(time_reg, reg_filter)] in the function _get_time.

Can I ask you why you have chosen to do the function calls as: MCP7940.int_to_bcd and MCP7940.bcd_to_int and not through self.int_to_bcd or self.bcd_to_int ?

Extract utility functions

There are some generally useful functions that should not be contained in MCP7940. The following functions are candidates:

  • is_leap_year
  • bcd_to_int/int_to_bcd
  • _set_bit/_read_bit

The corresponding tests should also be moved.

Leap Year bit in month register needs to be masked on read

Since 2020 is a leap year, the leap year bit is being set in the month register and was throwing off the month returned by x20 when getting mcp7940 time. I changed the mask for that register from x3F to x1F:

def _get_time(self, start_reg = 0x00):
    num_registers = 7 if start_reg == 0x00 else 6
    time_reg = self._i2c.readfrom_mem(MCP7940.ADDRESS, start_reg, num_registers)  # Reading too much here for alarms
    # reg_filter = (0x7F, 0x7F, 0x3F, 0x07, 0x3F, 0x3F, 0xFF)[:num_registers]
    # changed month mask from x3F to x1F to mask off leap year bit
    reg_filter = (0x7F, 0x7F, 0x3F, 0x07, 0x3F, 0x1F, 0xFF)[:num_registers]

Add alarm support

The MCP supports two alarms; need to add to the API.

Maybe:

mcp.alarm1.time = alarmtime # Set to None to stop alarm?
mcp.alarm.mask = # An OR'd enum here?
mcp.alarm1.time # Read alarm
mcp.alarm2.time = alarmtime2 

Add support for output features (Square wave and GPIO)

The MCP has various output configurations that can control the MFP pin. The alarm output is the most commonly used; MFP will be modified when the alarms are raised.

However there is support to also generate a square wave or a GPIO signal if the alarm output is not configured. These features should be exposed.

setup

Hi,

How install it on micropython ?

Sincerely
Eric

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.