Skip to content
This repository was archived by the owner on Dec 22, 2018. It is now read-only.

Commit 2d8f737

Browse files
committed
Initial commit.
1 parent bdfbdd5 commit 2d8f737

File tree

2 files changed

+177
-0
lines changed

2 files changed

+177
-0
lines changed

.travis.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Travis CI configuration for automated .mpy file generation.
2+
# Author: Tony DiCola
3+
# License: Public Domain
4+
# This configuration will work with Travis CI (travis-ci.org) to automacially
5+
# build .mpy files for MicroPython when a new tagged release is created. This
6+
# file is relatively generic and can be shared across multiple repositories by
7+
# following these steps:
8+
# 1. Copy this file into a .travis.yml file in the root of the repository.
9+
# 2. Change the deploy > file section below to list each of the .mpy files
10+
# that should be generated. The config will automatically look for
11+
# .py files with the same name as the source for generating the .mpy files.
12+
# Note that the .mpy extension should be lower case!
13+
# 3. Commit the .travis.yml file and push it to GitHub.
14+
# 4. Go to travis-ci.org and find the repository (it needs to be setup to access
15+
# your github account, and your github account needs access to write to the
16+
# repo). Flip the 'ON' switch on for Travis and the repo, see the Travis
17+
# docs for more details: https://docs.travis-ci.com/user/getting-started/
18+
# 5. Get a GitHub 'personal access token' which has at least 'public_repo' or
19+
# 'repo' scope: https://help.github.com/articles/creating-an-access-token-for-command-line-use/
20+
# Keep this token safe and secure! Anyone with the token will be able to
21+
# access and write to your GitHub repositories. Travis will use the token
22+
# to attach the .mpy files to the release.
23+
# 6. In the Travis CI settings for the repository that was enabled find the
24+
# environment variable editing page: https://docs.travis-ci.com/user/environment-variables/#Defining-Variables-in-Repository-Settings
25+
# Add an environment variable named GITHUB_TOKEN and set it to the value
26+
# of the GitHub personal access token above. Keep 'Display value in build
27+
# log' flipped off.
28+
# 7. That's it! Tag a release and Travis should go to work to add .mpy files
29+
# to the release. It takes about a 2-3 minutes for a worker to spin up,
30+
# build mpy-cross, and add the binaries to the release.
31+
language: generic
32+
33+
sudo: true
34+
35+
deploy:
36+
provider: releases
37+
api_key: $GITHUB_TOKEN
38+
file:
39+
- "framebuf.mpy"
40+
skip_cleanup: true
41+
on:
42+
tags: true
43+
44+
before_install:
45+
- sudo apt-get -yqq update
46+
- sudo apt-get install -y build-essential git python python-pip
47+
- git clone https://github.com/adafruit/micropython.git
48+
- make -C micropython/mpy-cross
49+
- export PATH=$PATH:$PWD/micropython/mpy-cross/
50+
- sudo pip install shyaml
51+
52+
before_deploy:
53+
- shyaml get-values deploy.file < .travis.yml | sed 's/.mpy/.py/' | xargs -L1 mpy-cross

framebuf.py

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
# Pure python implementation of MicroPython framebuf module.
2+
# This is intended for boards with limited flash memory and the inability to
3+
# use the native C version of the framebuf module. This python module can be
4+
# added to the board's file system to provide a functionally identical framebuf
5+
# interface but at the expense of speed (this python version will be _much_
6+
# slower than the C version).
7+
# This is a direct port of the framebuf module C code to python:
8+
# https://github.com/micropython/micropython/blob/master/extmod/modframebuf.c
9+
# Original file created by Damien P. George.
10+
# Python port below created by Tony DiCola.
11+
12+
13+
# Framebuf format constats:
14+
MVLSB = 0 # Single bit displays (like SSD1306 OLED)
15+
RGB565 = 1 # 16-bit color displays
16+
GS4_HMSB = 2 # Unimplemented!
17+
18+
19+
class MVLSBFormat:
20+
21+
def setpixel(self, fb, x, y, color):
22+
index = (y >> 3) * fb.stride + x
23+
offset = y & 0x07
24+
fb.buf[index] = (fb.buf[index] & ~(0x01 << offset)) | ((color != 0) << offset)
25+
26+
def getpixel(self, fb, x, y):
27+
index = (y >> 3) * fb.stride + x
28+
offset = y & 0x07
29+
return ((fb.buf[index] >> offset) & 0x01)
30+
31+
def fill_rect(self, fb, x, y, width, height, color):
32+
while height > 0:
33+
index = (y >> 3) * fb.stride + x
34+
offset = y & 0x07
35+
for ww in range(width):
36+
fb.buf[index+ww] = (fb.buf[index+ww] & ~(0x01 << offset)) | ((color != 0) << offset)
37+
y += 1
38+
height -= 1
39+
40+
41+
class RGB565Format:
42+
43+
def setpixel(self, fb, x, y, color):
44+
index = (x + y * fb.stride) * 2
45+
fb.buf[index] = (color >> 8) & 0xFF
46+
fb.buf[index+1] = color & 0xFF
47+
48+
def getpixel(self, fb, x, y):
49+
index = (x + y * fb.stride) * 2
50+
return (fb.buf[index] << 8) | fb.buf[index+1]
51+
52+
def fill_rect(self, fb, x, y, width, height, color):
53+
while height > 0:
54+
for ww in range(width):
55+
index = (ww + x + y * fb.stride) * 2
56+
fb.buf[index] = (color >> 8) & 0xFF
57+
fb.buf[index+1] = color & 0xFF
58+
y += 1
59+
height -= 1
60+
61+
62+
class FrameBuffer:
63+
64+
def __init__(self, buf, width, height, buf_format=MVLSB, stride=None):
65+
self.buf = buf
66+
self.width = width
67+
self.height = height
68+
self.stride = stride
69+
if self.stride is None:
70+
self.stride = width
71+
if buf_format == MVLSB:
72+
self.format = MVLSBFormat()
73+
elif buf_format == RGB565:
74+
self.format = RGB565Format()
75+
else:
76+
raise ValueError('invalid format')
77+
78+
def fill(self, color):
79+
self.format.fill_rect(self, 0, 0, self.width, self.height, color)
80+
81+
def fill_rect(self, x, y, width, height, color):
82+
if width < 1 or height < 1 or (x+width) <= 0 or (y+height) <= 0 or y >= self.height or x >= self.width:
83+
return
84+
xend = min(self.width, x+width)
85+
yend = min(self.height, y+height)
86+
x = max(x, 0)
87+
y = max(y, 0)
88+
self.format.fill_rect(self, x, y, xend-x, yend-y, color)
89+
90+
def pixel(self, x, y, color=None):
91+
if x < 0 or x >= self.width or y < 0 or y >= self.height:
92+
return
93+
if color is None:
94+
return self.format.getpixel(self, x, y)
95+
else:
96+
self.format.setpixel(self, x, y, color)
97+
98+
def hline(self, x, y, width, color):
99+
self.fill_rect(x, y, width, 1, color)
100+
101+
def vline(self, x, y, height, color):
102+
self.fill_rect(x, y, 1, height, color)
103+
104+
def rect(self, x, y, width, height, color):
105+
self.fill_rect(x, y, width, 1, color)
106+
self.fill_rect(x, y+height, width, 1, color)
107+
self.fill_rect(self, x, y, 1, height, color)
108+
self.fill_rect(self, x+width, y, 1, height, color)
109+
110+
def line(self):
111+
raise NotImplementedError()
112+
113+
def blit(self):
114+
raise NotImplementedError()
115+
116+
def scroll(self):
117+
raise NotImplementedError()
118+
119+
def text(self):
120+
raise NotImplementedError()
121+
122+
123+
class FrameBuffer1(FrameBuffer):
124+
pass

0 commit comments

Comments
 (0)