-
Notifications
You must be signed in to change notification settings - Fork 100
More int type fixes and tests for drivers #80
Conversation
Not sure how that is "making the language more simple", but whatever. Just one comment above |
@@ -121,7 +121,7 @@ impl<'a, S: SPI, T: Timer, P: GPIO> C12332<'a, S, T, P> { | |||
let index = x + (y/8) * 128; | |||
if color == 0 { | |||
self.videobuf[index as uint].set( | |||
self.videobuf[index as uint].get() & !(1 << (y%8) as uint) as u8); | |||
self.videobuf[index as uint].get() & !(1i32 << (y%8i32) as uint) as u8); |
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.
Why is this signed int? it's getting downcasted to u8
, so using u8
should be fine.
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.
You are right!
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.
Ok, that gives me another error:
/Users/ilya/Code/Work/rust/zinc/src/drivers/lcd/c12332.rs:124:58: 124:61 error: mismatched types: expected `i32` but found `i8` (expected i32 but found i8)
/Users/ilya/Code/Work/rust/zinc/src/drivers/lcd/c12332.rs:124 self.videobuf[index as uint].get() & !(1i8 << (y%8i8) as uint) as u8);
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.
Ah. so, y
being i32
is kind of a bug, as you cannot really address any pixel < 0. If you have some time to work on this, can you please update function definition to read pub fn set_pixel(&self, x: u32, y: u32, color: u16)
? Then the addressing should be something along the lines of (1u8 << (y % 8u32) as uint) as u8
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.
yes, that's what I was thinking, but wasn't sure...
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.
And is this a bug as well?
src/drivers/lcd/mod.rs: fn pixel(&self, x: i32, y: i32, color: u16);
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.
Yes, that one as well.
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.
Ok, will fix it.
I won't be surprised it will go away. May be we need refactor those kind of expressions somehow? |
Most of that is bits manipulation. It would be nice to have some macro to do that in a better (and more safe way). |
It certainly needs some nice macros. |
Looks a little cleaner now 😄 |
A bit mode cleaning please: https://travis-ci.org/errordeveloper/zinc/jobs/28985715#L103 |
Yeah... The warning, wasn't quite sure what's the fix...
|
In c12332 — it's safe to remove the check for In lcd/mod.rs — you actually broke the algorithm, all the variables other than |
So 35440a6 fixes C12332. And for the broken algorithm I'm thinking of fixing it with |
No, di must be |
Well, if they are unsigned, they will never be less then zero, it will
|
So in terms of geometry, what does the zero represent here? Is it more like |
@farcaller I'm thinking that we should have test for this, generate a bitmap and compare it to a static bitmap, what do you think? |
Ok. I can run the test on actual hw this weekend, but you can go on and make an unit test. |
Yeah, I'd love to! Might need a little help, if you don't mind... Will ping
|
Will re-open when unit tests are done. |
@farcaller this is on top of #89. |
source: 'main.rs'.in_source, | ||
deps: [:core_crate], | ||
produce: 'zinc_test'.in_build, | ||
recompile_on: [:triple, :platform, :features], |
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.
Do not recompile on :triple, host triple isn't going to change.
fn should_fill_and_clear() { | ||
let io = TestLCD::new(); | ||
io.set_fill(128); | ||
io.for_each(|_, x| { |
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.
io.for_each(|_, x| assert!(x == 128));
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.
ok, so generally make things like this to one line unless it's too long?
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.
the syntax is actually nicer then Ruby!
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.
Right. you don't need curly braces if the statement is simple, if it spans a few lines you still add them for readability (although it's syntactically correct to drop them).
I think you can do with a much smaller buffer, like 5x5 pixels, this way you can make a helper test case macro that makes a call and verifies it by the "picture". Bonus points if you define the template with something like let match = "
.....
.XXXX
.X..X
.XXXX
....." |
@farcaller regarding the buffer, I though might as well print a letter using |
Travis might have hit a rustc bug, but I'd rather rebase this on #92 first. I'm also thinking to squash this down to a couple of commits. From 15 to 3 or 5, perhaps... |
Does anyone else want to review this or we can merge? |
Please remove this test: |
Removed. Should I squash or it's okay? |
|
||
io.line(0, 0, 15, 15, 1); | ||
|
||
// TODO: investigate why this hangs the test run in `__psynch_cvwait()` |
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 'own' the todo: // TODO(errordeveloper): ...
Yes, you can squash it a bit (reasonably). |
- pixel coordinates are always unsigned - use `for ... in range(...)` instead of `while ...`
fn line(&self, x0_b: u32, y0_b: u32, x1: u32, y1: u32, color: u16) { | ||
let mut x0: u32 = x0_b; | ||
let mut y0: u32 = y0_b; | ||
let mut dx: u32; |
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.
Do these dx want to be i32?
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.
dx, dy, dx_sym and dy_sym at the minimum should be signed. This should fix your hanging test.
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.
And it might be nicer if you get rid of the 'mut' and just rebind with another let statement. di, x0 and y0 should be mut.
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.
Yes, those must me signed, as dx = x1-x0
may be less than zero as we discussed above. @errordeveloper, please fix and re-enable the 15,15 -> 0,0 test, it should work.
@bharrisau, thanks for catching that.
Tests looks great. Thanks for this. |
- fix hanging test by fixing signed/unsigned types - get rid of C copypastaz and not needed mut vars - more refactoring of while loops
We don't get any notifications when you update things - so you need to post here if you are ready for review. |
Well, I do have notifications for stale "ready for review" PRs, but the script is broken :) |
A simple r? should be fine. I don't think non-contributors can update |
oh well. yes, then a simple 'r?' is fine, somehow I missed the permissions bit. |
So is this good to merge now? |
Yup, thanks for your work. |
More int type fixes and tests for drivers Reviewed-by: farcaller
Just pulled in nightly and got a whole bunch of errors like this:
Not sure, may be this just a follow-up on rust-lang/rust#6023?